Skip to content

Commit

Permalink
ex3 cost function
Browse files Browse the repository at this point in the history
  • Loading branch information
hcfw007 committed Apr 27, 2019
1 parent ebec689 commit f418c31
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions machine-learning-ex3/ex3/lrCostFunction.m
Expand Up @@ -38,10 +38,12 @@



h = sigmoid(X * theta);
J = (1 / m) * sum(- y .* log(h) - (1 - y) .* log(1 - h)) + lambda / (2 * m) * (theta(2: end)' * theta(2: end));
grad = (1 / m) * X' * (h - y);




grad(1) = X(:, 1)' * (h - y) / m;
grad(2: end) = (X(:, 2: end)' * (h - y) + lambda * theta(2: end)) / m;



Expand Down

0 comments on commit f418c31

Please sign in to comment.