Skip to content

Instantly share code, notes, and snippets.

@junichiro
Last active March 7, 2018 02:36
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 junichiro/f88d2d4e4b94b18f8a08573569b35052 to your computer and use it in GitHub Desktop.
Save junichiro/f88d2d4e4b94b18f8a08573569b35052 to your computer and use it in GitHub Desktop.
機械学習を1ヵ月で実践レベルにする #10 (正則化) ref: https://qiita.com/junichiro/items/8b1867201663c5af38a4
hx = X * theta;
cost = hx - y;
theta = [0; theta(2:end, :)];
J = ((cost' * cost) + lambda * (theta' * theta)) / (2 * m);
grad = (X' * cost + lambda * theta) / m;
J = -1/m * sum(y .* log(sigmoid(X * theta)) + (1 - y) .* log(1 - sigmoid(X * theta))) + lambda / 2 /m * sum(theta(2:end,:).^2);
grad = 1/m * (X' * (sigmoid(X * theta) - y)) + lambda / m * [0 ; theta(2:size(theta), :)];;
grad = 1/m * (X' * (sigmoid(X * theta) - y)) + lambda / m * [0 ; theta(2:size(theta), :)];;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment