Andrew Ng在coursera上的机器学习公开课 自己写的部分编程答案,留作记录,欢迎交流
computeCost.m
m=size(X,1);
h=(X*theta-y).^2;
% You need to return the following variables correctly
J = 1/(2*m)*sum(h);
computeCostMulti.m
m=size(X,1);
h=(X*theta-y).^2;
% You need to return the following variables correctly
J = 1/(2*m)*sum(h);
gradientDescent.m
theta=theta-(1/m)*alpha*(sum((sum(theta'.*X,2)-y).*(X),1))';
gradientDescentMulti.m
theta=theta-(1/m)*alpha*(sum((sum(theta'.*X,2)-y).*(X),1))';