1
0
Fork 0

Add regularization to the cost function

master
neingeist 10 years ago
parent f2154a8cc1
commit 395c5676dc

@ -80,23 +80,14 @@ assert(size(J) == [1 1]);
% and Theta2_grad from Part 2.
%
% Note: Theta1/2 are matrixes here, we want all their rows, but skip their
% first column (not regularizing the bias term).
regularization_term = lambda/(2*m) * ...
(sum(sum(Theta1(:,2:end).^2)) ...
+ sum(sum(Theta2(:,2:end).^2)));
assert(size(regularization_term) == [1 1]);
J += regularization_term;
% -------------------------------------------------------------