Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Machine learning 机器学习中的梯度下降算法_Machine Learning_Gradient Descent - Fatal编程技术网

Machine learning 机器学习中的梯度下降算法

Machine learning 机器学习中的梯度下降算法,machine-learning,gradient-descent,Machine Learning,Gradient Descent,我是机器学习的初学者。我在梯度下降算法方面有问题。在下面提到的代码中,我的疑问是 x的第一次迭代值为1 x的第二次迭代值为2 x的第三次迭代值为3 x的第四次迭代值为4 x的第五次迭代值为5 那么迭代6到9999的x值是多少 import numpy as np import matplotlib.pyplot as plt %matplotlib inline def gradient_descent(x,y): m_curr = b_curr = 0 rate = 0

我是机器学习的初学者。我在梯度下降算法方面有问题。在下面提到的代码中,我的疑问是

x的第一次迭代值为1

x的第二次迭代值为2

x的第三次迭代值为3

x的第四次迭代值为4

x的第五次迭代值为5

那么迭代6到9999的x值是多少

import numpy as np

import matplotlib.pyplot as plt

%matplotlib inline

def gradient_descent(x,y):

    m_curr = b_curr = 0
    rate = 0.01
    n = len(x)
    plt.scatter(x,y,color='red',marker='+',linewidth='5')
    for i in range(10000):
        y_predicted = m_curr * x + b_curr
        plt.plot(x,y_predicted,color='green')
        md = -(2/n)*sum(x*(y-y_predicted))
        yd = -(2/n)*sum(y-y_predicted)
        m_curr = m_curr - rate * md
        b_curr = b_curr - rate * yd

x = np.array([1,2,3,4,5])

y = np.array([5,7,9,11,13])

gradient_descent(x,y)

计算批次梯度的三种变体

  • 批处理
  • 随机的
  • 小批量
  • 我相信您正在尝试实施批处理变体。如果是这种情况,您需要执行以下操作

  • 将for循环更改为运行,直到x或y的大小。i、 e.
    len(x)
  • 在另一个for循环中调用gradient_degence(x,y),循环次数为10000(或者您希望运行的迭代次数)。您可能应该使用错误函数来确定这一点

  • 请正确设置代码块的格式。您没有修改
    x
    ???Aravind R.Yarram,在随机的情况下,len(x)应该等于迭代次数???