1-Change this code from Matlab to Phython: * Compute and display initial cost and gradient for regularized logistic regression [cost, grad] = costFunctionReg (initial_theta, x, y, lambda); fprintf...


1-Change this code from Matlab to Phython:<br>* Compute and display initial cost and gradient for regularized logistic regression<br>[cost, grad] = costFunctionReg (initial_theta, x, y, lambda);<br>fprintf ('Cost at initial theta (zeros): %f\n', cost);<br>28 fprintf ('Expected cost (approx) : 0.693\n');<br>29 fprintf('Gradient at initial theta (zeros) - first five values only:\n');<br>30 fprintf (' %f \n', grad (1:5));<br>31 fprintf ('Expected gradients (approx)<br>fprintf (' 0.0085\n 0.0188\n 0.0001\n 0.0503\n 0.0115\n');<br>33 % Compute and display cost and gradient with all-ones theta and lambda = 10<br>test_theta<br>[cost, grad] =<br>24<br>25<br>26<br>27<br>first five values only:\n');<br>32<br>ones (size (X, 2),1);<br>costFunctionReg (test_theta, X, y, 10);<br>34<br>35<br>10): %f\n', cost);<br>36 fprintf ('\nCost at test theta (with lambda<br>37 fprintf ('Expected cost (approx) : 3.16\n');<br>38 fprintf('Gradient at test theta<br>39 fprintf (' %f \n', grad (1:5));<br>fprintf ('Expected gradients (approx)<br>first five values only:\n');<br>40<br>first five values only:\n');<br>41<br>fprintf (' 0.3460\n 0.1614\n 0.1948\n 0.2269\n 0.0922\n');<br>

Extracted text: 1-Change this code from Matlab to Phython: * Compute and display initial cost and gradient for regularized logistic regression [cost, grad] = costFunctionReg (initial_theta, x, y, lambda); fprintf ('Cost at initial theta (zeros): %f\n', cost); 28 fprintf ('Expected cost (approx) : 0.693\n'); 29 fprintf('Gradient at initial theta (zeros) - first five values only:\n'); 30 fprintf (' %f \n', grad (1:5)); 31 fprintf ('Expected gradients (approx) fprintf (' 0.0085\n 0.0188\n 0.0001\n 0.0503\n 0.0115\n'); 33 % Compute and display cost and gradient with all-ones theta and lambda = 10 test_theta [cost, grad] = 24 25 26 27 first five values only:\n'); 32 ones (size (X, 2),1); costFunctionReg (test_theta, X, y, 10); 34 35 10): %f\n', cost); 36 fprintf ('\nCost at test theta (with lambda 37 fprintf ('Expected cost (approx) : 3.16\n'); 38 fprintf('Gradient at test theta 39 fprintf (' %f \n', grad (1:5)); fprintf ('Expected gradients (approx) first five values only:\n'); 40 first five values only:\n'); 41 fprintf (' 0.3460\n 0.1614\n 0.1948\n 0.2269\n 0.0922\n');

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here