Created
May 26, 2012 23:09
-
-
Save anuvrat/2795575 to your computer and use it in GitHub Desktop.
Performs gradient descent to learn 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
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) | |
%GRADIENTDESCENT Performs gradient descent to learn theta | |
% theta = GRADIENTDESENT(X, y, theta, alpha, num_iters) updates theta by | |
% taking num_iters gradient steps with learning rate alpha | |
% Initialize some useful values | |
m = length(y); % number of training examples | |
J_history = zeros(num_iters, 1); | |
for iter = 1:num_iters | |
theta = theta - (X' * (X * theta - y)) * (alpha / m); | |
% Save the cost J in every iteration | |
J_history(iter) = computeCost(X, y, theta); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
forgive me, i just was wondering about what X' * mean i am new to matlab and these symbol really confuse me as i was trying to figure out what it means