Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

solution with one line #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions mlclass-ex1/gradientDescent.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@
%


x = X(:,2);
h = theta(1) + (theta(2)*x);

theta_zero = theta(1) - alpha * (1/m) * sum(h-y);
theta_one = theta(2) - alpha * (1/m) * sum((h - y) .* x);

theta = [theta_zero; theta_one];
% ============================================================

% Save the cost J in every iteration
J_history(iter) = computeCost(X, y, theta);
% disp(J_history(iter));
%this is also possible in one line
theta = theta - alpha * (1/m) * sum((X * theta - y) .* X)';

end

disp(min(J_history));
end
end