八度循环错误

Octave- looping error

我正在从 Cousera 进行机器学习,它为线性回归分配产生了一个错误,我不明白这是什么问题。我在 windows 10 上使用 Octave 4.0。这是代码:

function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
  m         = length(y); % number of training examples
  hypo      = [m,1];
  J_history = zeros(num_iters, 1);

  for iter = 1: num_iters

    % ====================== YOUR CODE HERE ======================
    % Instructions: Perform a single gradient step on the parameter vector
    %               theta. 
    %
    % Hint: While debugging, it can be useful to print out the values
    %       of the cost function (computeCost) and gradient here.
    %

    hypo  = theta(1) + theta(2) * X;
    temp1 = theta(1) - alpha * (1 / m) * sum(hypo);

    hypo  = theta(1) + theta(2) * X;
    temp2 = theta(2) - alpha * (1 / m) * sum((hypo .* X));  

    theta = [temp1; temp2];
    % ===========================================================

    % Save the cost J in every iteration    
    J_history(iter) = computeCost(X, y, theta);

  end

  predict1 = [1, 3.5] * theta;
  predict2 = [1, 7.0] * theta;

end

它在

处产生循环错误 "A(I)= X:X same size as I"
 J_history(iters) = computeCost(X, y, theta);

不鼓励讨论课程练习的代码,所以我不会为您解决这个问题。我只是给你一个指点。

computeCost 期望 theta 的大小为 2,1,而 theta 您 post 作为参数的大小为 2,2。使用命令 keyboard 到 break/pause 在特定行执行,并进入控制台会话进行调试。检查你post变量的维度。您可以使用 dbcont.

恢复执行