Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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
Python 如何在不使用矩阵运算的情况下对迭代梯度下降进行编码?_Python_Machine Learning_Gradient Descent - Fatal编程技术网

Python 如何在不使用矩阵运算的情况下对迭代梯度下降进行编码?

Python 如何在不使用矩阵运算的情况下对迭代梯度下降进行编码?,python,machine-learning,gradient-descent,Python,Machine Learning,Gradient Descent,我被要求在python中为一个变量编写迭代梯度下降代码。我的X集合有一列1表示X0,之后有一列X1值。集合y有一列值。θ是随机设置的,α是一个常数 for iteration in iterations: sum0 = 0 sum1 = 0 m = len(X) for i in range(0,m): sum0 += (X[i,1] * thetas[1]) + thetas[0] - y[i] sum1 += ((X[i,1]

我被要求在python中为一个变量编写迭代梯度下降代码。我的X集合有一列1表示X0,之后有一列X1值。集合y有一列值。θ是随机设置的,α是一个常数

for iteration in iterations:
    sum0 = 0
    sum1 = 0
    m = len(X)
    for i in range(0,m):
        sum0 += (X[i,1] * thetas[1]) + thetas[0] - y[i]
        sum1 += ((X[i,1] * thetas[1]) + thetas[0] - y[i]) * X[i,1]
    temp0 = thetas[0] - ((alpha / m) * sum0)
    temp1 = thetas[1] - ((alpha / m) * sum1)
    thetas[0] = temp0
    thetas[1] = temp1
我的问题是,在这段代码的100次迭代中,成本值似乎保持在1。

也许这对您有所帮助。您可以自己驱动非扇区格式。