【发布时间】:2012-05-22 09:50:57
【问题描述】:
我实际上已经为此苦苦挣扎了 2 个月。是什么让这些不同?
hypotheses= X * theta
temp=(hypotheses-y)'
temp=X(:,1) * temp
temp=temp * (1 / m)
temp=temp * alpha
theta(1)=theta(1)-temp
hypotheses= X * theta
temp=(hypotheses-y)'
temp=temp * (1 / m)
temp=temp * alpha
theta(2)=theta(2)-temp
theta(1) = theta(1) - alpha * (1/m) * ((X * theta) - y)' * X(:, 1);
theta(2) = theta(2) - alpha * (1/m) * ((X * theta) - y)' * X(:, 2);
后者有效。我只是不确定为什么..我很难理解对矩阵逆的需要。
【问题讨论】:
-
我不认为这是梯度下降的正确实现。你需要更新。你的两个 theta 同时是准确的。
tmpTheta1= theta(1) - alpha * (1/m) * ((X * theta) - y)' * X(:, 1); tmpTheta2= theta(2) - alpha * (1/m) * ((X * theta) - y)' * X(:, 2);theta(1)=tmpTheta1;theta(2)=tmpTheta2;
标签: octave