Skip to content

Instantly share code, notes, and snippets.

@vijaykiran
Created November 20, 2011 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaykiran/1380992 to your computer and use it in GitHub Desktop.
Save vijaykiran/1380992 to your computer and use it in GitHub Desktop.
predictions = X * theta; %number of traing examples on m examples                                                                                            
                                                                                                                                                             
sqrErrors = (predictions - y).^2; % squared errors                                                                                                            
J = (1 / (2 *m) * sum(sqrErrors) ) + sum(theta(2:end) .^ 2) * lambda / (2 * m);                                                                              
grad = (1 / m) * ((X' * (predictions - y)) + (lambda * theta));                                                                                              
grad(1) -= (1 / m ) * (lambda * theta(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment