【发布时间】:2019-06-03 20:58:11
【问题描述】:
我最近尝试在 octave 中实现线性回归,但无法通过在线评委。这是代码
function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
m = length(y); % number of training examples
J_history = zeros(num_iters, 1);
for iter = 1:num_iters
for i = 1:m
temp1 = theta(1)-(alpha/m)*(X(i,:)*theta-y(i,:));
temp2 = theta(2)-(alpha/m)*(X(i,:)*theta-y(i,:))*X(i,2);
theta = [temp1;temp2];
endfor
J_history(iter) = computeCost(X, y, theta);
end
end
我知道矢量化实现,但只是想尝试迭代方法。任何帮助将不胜感激。
【问题讨论】:
标签: machine-learning octave linear-regression gradient-descent