机器学习 Andrew Ng《Machine Learning》

2020-02-03  本文已影响0人  妖小灰

coursera---机器学习

第2周 编程作业: Linear Regression


原文链接:
https://sun2y.me

环境

Windows 10
Octave 5.1.0

问题

解决方案:
在当前目录新建文件pause.m, 内容如下:

input('Press Enter to continue: ', 's');

作业代码

Plotting

plotData.m

plot(x, y, 'rx', 'MarkerSize', 10);
xlabel('population')
ylabel('profit')

Cost and Gradient descent

computeCost.m

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

gradientDescent

    theta0 = theta(1,1) - alpha * sum(X * theta - y) / m;
    theta1 = theta(2,1) - alpha *  sum((X * theta - y) .* X(:,2)) / m;

    theta = [theta0; theta1]
上一篇 下一篇

猜你喜欢

热点阅读