Last active
January 10, 2017 09:09
-
-
Save junichiro/42efe91b8a94fe1ec6e801c092bc6e83 to your computer and use it in GitHub Desktop.
機械学習を1ヵ月で実践レベルにする #5 (線形回帰 Octave 実装) ref: http://qiita.com/junichiro/items/1a4b87e99b471cf5bea1
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
function J = computeCost(X, y, theta) | |
m = length(y); | |
J = 1/2/m * sum((X * theta - y).^2); | |
end |
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
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) | |
m = length(y); | |
for iter = 1:num_iters | |
theta = theta - alpha / m * X' * (X * theta -y); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment