【发布时间】:2018-07-13 02:11:19
【问题描述】:
在完成此功能时需要帮助。尝试找出 derJ 时出错:
error: X(0,_): subscripts must be either integers 1 to (2^63)-1 or logicals
我的代码:
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
predictions = X * theta; % hypothesis
% derivative term for cost function
derJ = (1 / m) * sum ( (predictions - y) * X(iter-1, 2) );
% updating theta values
theta = theta - (alpha * derJ);
J_history(iter) = computeCost (X, y, theta);
end
end
【问题讨论】:
标签: machine-learning octave gradient-descent