1
0
Fork 0

Vectorized regularized logistic regression, again

master
neingeist 10 years ago
parent 326a924044
commit 9117809537

@ -27,6 +27,10 @@ grad = zeros(size(theta));
% prediction for that example. You can make use of this to vectorize
% the cost function and gradient computations.
%
J = 1/m * (-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta))) ...
+ lambda/(2*m) * theta(2:end)' * theta(2:end);
% Hint: When computing the gradient of the regularized cost function,
% there're many possible vectorized solutions, but one solution
% looks like:
@ -36,14 +40,8 @@ grad = zeros(size(theta));
% grad = grad + YOUR_CODE_HERE (using the temp variable)
%
regularization_term = lambda/m * vertcat([0], theta(2:end));
grad = 1/m * X' * (sigmoid(X*theta) - y) + regularization_term;
% =============================================================