Skip to content

Instantly share code, notes, and snippets.

@junichiro
Last active January 10, 2017 09:09
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/42efe91b8a94fe1ec6e801c092bc6e83 to your computer and use it in GitHub Desktop.
Save junichiro/42efe91b8a94fe1ec6e801c092bc6e83 to your computer and use it in GitHub Desktop.
機械学習を1ヵ月で実践レベルにする #5 (線形回帰 Octave 実装) ref: http://qiita.com/junichiro/items/1a4b87e99b471cf5bea1
function J = computeCost(X, y, theta)
m = length(y);
J = 1/2/m * sum((X * theta - y).^2);
end
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