1. 程式人生 > >MOOC Machine learning 作業交流帖1

MOOC Machine learning 作業交流帖1

wk1 Linear Regression

最近正在學習MOOC上的經典課程:Machine learning (by Andrew Ng), 具體課程連結:MACHINE LEARNING
根據進度將作業的關鍵程式碼部分貼上,僅供交流與討論。

  • computeCost
J=sum((X*theta-y).^2)/(2*m);
  • gradientDescent
theta = theta - (1/m)*alpha*(X.'*(X*theta-y));
J_history(iter) = computeCost(X, y, theta);
  • featureNormalize
mu=mean(X,1);
sigma = std(X);
X_norm = (X - ones(size(X, 1), 1) * mu) ./ (ones(size(X, 1), 1) * sigma);
  • computeCostMulti
J = (X * theta - y).' * (X * theta - y) / (2*m);
  • gradeDescentMulti
theta = theta - (1/m)*alpha*(X.'*(X*theta-y));
J_history(iter) = computeCostMulti(X, y, theta);
  • normalEqn
theta=(inv(X.'*X))*X.'*y;

——轉載請註明出處