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