Last active
August 25, 2017 06:52
-
-
Save parachvte/6ba6c3cdf5c13f16c898bd74efa273d5 to your computer and use it in GitHub Desktop.
Logistic Regression Cost Function (Regularized)
This file contains hidden or 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 | |
| h = sigmoid(X * theta); | |
| J = mean(-y .* log(h) - (1 - y) .* log(1 - h)) ... | |
| + lambda / 2.0 / m * (sum(theta .^ 2) - theta(1) ^ 2); | |
| grad = X' * (h - y) / m + lambda / m * theta; | |
| grad(1) -= lambda / m * theta(1); | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment