1
0
Fork 0

Simplify regularization term

master
neingeist 10 years ago
parent 9e9b9990bb
commit f9243ef593

@ -20,8 +20,7 @@ grad = zeros(size(theta));
J = 1/m * (-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta))) ... J = 1/m * (-y'*log(sigmoid(X*theta)) - (1-y)'*log(1-sigmoid(X*theta))) ...
+ lambda/(2*m) * theta(2:end)' * theta(2:end); + lambda/(2*m) * theta(2:end)' * theta(2:end);
regularization_term = ... regularization_term = lambda/m * vertcat([0], theta(2:end));
lambda/m * (theta .* prepad(ones(length(theta)-1, 1), length(theta), 0));
grad = 1/m * X' * (sigmoid(X*theta) - y) + regularization_term; grad = 1/m * X' * (sigmoid(X*theta) - y) + regularization_term;
% ============================================================= % =============================================================