Machine Learning 第一波编程作业 – Linear Regression

仅列出核心代码:

1.computeCost

J = sum((X*theta-y).^2)/(2*m);

2.gradientDescent

theta = theta – (1/m)*alpha*(X.’*(X*theta-y));

3.featureNormalize

mu = mean(X);
sigma = std(X);
X_norm = (X – ones(size(X, 1), 1) * mu) ./ (ones(size(X, 1), 1) * sigma);

4.computeCostMulti

J = (X * theta – y).’ * (X * theta – y) / (2*m);

5.gradientDescentMulti

theta = theta – (1/m)*alpha*(X.’*(X*theta-y));

6.normalEqn

theta = inv(X.’ * X) * X.’ * y;

课程地址:https://www.coursera.org/course/ml

Advertisements
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s