Machine learning 梯度下降倍频程码
需要帮助完成此功能。尝试查找derJ时出错:Machine learning 梯度下降倍频程码,machine-learning,octave,gradient-descent,Machine Learning,Octave,Gradient Descent,需要帮助完成此功能。尝试查找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_
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
您的代码状态为X(iter-1,2)
,但在for循环中iter
从1
开始
因此,在第一次迭代中,X(iter-1,2)
将计算为X(0,2)
,并且0
在matlab中不是有效的索引