为什么梯度下降不能在后续输入中收敛?

时间:2019-11-22 14:47:56

标签: machine-learning gradient-descent

此代码正在使用“梯度下降”,并且其输入不收敛。为什么会这样?

import numpy as np 
inputs = np.array([[1.8,1.2],[4,5]])
output = np.array([1.7,7])
weight = np.array([0.5,0.5])
alpha = 0.1

for j in range(100):
    all_error = 0 
    for i in range(len(inputs)):
        #print("Input:  "+str(inputs[i])+"     weight:"+str(weight))
        prediction=inputs[i].dot(weight)
        #print("Prediction:  " + str(prediction))
        slope = prediction - output[i]
        weight =  weight - slope * alpha * inputs[i]
        error = (prediction - output[i])**2
        all_error += error
    print("Error:  "+str(all_error))
#print(inputs.dot(weight))

0 个答案:

没有答案