【问题标题】:Gradient Descent Octave Code梯度下降八度码
【发布时间】: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


    【解决方案1】:

    您的代码声明 X(iter - 1, 2),但在您的 for 循环中 iter1 开始。

    因此,在第一次迭代中,X(iter - 1, 2) 将评估为 X(0,2),而0 在 matlab 中不是有效索引。

    【讨论】:

      猜你喜欢
      • 2012-05-22
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2014-01-11
      • 2012-08-17
      相关资源
      最近更新 更多