Last active
January 31, 2022 22:40
-
-
Save Leon-Ray/9866616 to your computer and use it in GitHub Desktop.
Vectorized logistic regression with regularization using gradient descent for the Coursera course Machine Learning. Cost function (J) and partial derivatives of the cost w.r.t. each parameter in theta (grad).
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
len = size(theta); | |
J = 1/m*(-y'*log(sigmoid(X*theta))-(1-y)'*log(1-sigmoid(X*theta))) + lambda/(2*m)*sum(theta(2:len).^2); | |
grad = 1./m*((sigmoid(X*theta)-y)'*X); | |
temp = theta; | |
temp(1) = 0; | |
grad = grad + (lambda/m.*temp)'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment