Created
September 17, 2012 10:48
-
-
Save prakhar1989/3736661 to your computer and use it in GitHub Desktop.
regularization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [J, grad] = costFunctionReg(theta, X, y, lambda) | |
m = length(y); % number of training examples | |
J = 0; | |
grad = zeros(size(theta)); | |
[J, grad] = costFunction(theta, X,y); | |
reg = ( (sum(theta.^2) - theta(1,1)^2) * (lambda/(2*m)) ) | |
J = J + reg; | |
for iter = 1:size(grad), | |
if (iter) > 1, | |
grad(iter) = grad(iter) + theta(iter, 1) * lambda / m; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment