美文网首页
机器学习 Andrew Ng《Machine Learning》

机器学习 Andrew Ng《Machine Learning》

作者: 妖小灰 | 来源:发表于2020-02-03 22:16 被阅读0次

coursera---机器学习

第2周 编程作业: Linear Regression


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

环境

Windows 10
Octave 5.1.0

问题

  • 使用ex1命令,执行测试程序时,程序一次执行到底,pause没有起着作用

解决方案:
在当前目录新建文件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]

相关文章

网友评论

      本文标题:机器学习 Andrew Ng《Machine Learning》

      本文链接:https://www.haomeiwen.com/subject/vwxlxhtx.html