在 Octave 中编写单个梯度下降步骤

问题描述

给定梯度下降的步骤:

enter image description here

答案键有...

    function[theta,J_history] = gradientDescent(X,y,theta,alpha,num_iters)

    m = length(y); %number of training examples
    
    for iter = 1:num_iters

    error = (theta * X) - y;
    
    temp0 = theta(1) - ((alpha/m) * sum(error .* X(:,1)));
    temp1 = theta(2) - ((alpha/m) * sum(error .* X(:,2)));
    theta = [temp0; temp1];

    

当我自己编写代码时,除了 temp1 之外,我一切都正确。我想我对我们在步骤结束时乘以 Xi 的代码中的哪个位置感到困惑?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)