第2周 編程作業(yè): Linear Regression
原文鏈接:
https://sun2y.me
環(huán)境
Windows 10
Octave 5.1.0
問題
- 使用
ex1
命令蹂空,執(zhí)行測試程序時巴元,程序一次執(zhí)行到底,pause
沒有起著作用
解決方案:
在當(dāng)前目錄新建文件pause.m
, 內(nèi)容如下:
input('Press Enter to continue: ', 's');
作業(yè)代碼
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]