渐变下降发散,学习率过高

时间:2016-12-14 13:32:55

标签: python-3.x gradient-descent

下面有一段代码,它逐步完成GD,但theta正在发散。可能有什么不对?

X = arange(100)
Y = 50 + 4*X + uniform(-20, 20, X.shape)

theta = array([0,0])
alpha = 0.001
# one step of GD
theta0 = theta[0] - alpha * sum( theta[0]+theta[1]*x-y    for x,y in zip(X,Y))/len(X)
theta1 = theta[1] - alpha * sum((theta[0]+theta[1]*x-y)*x for x,y in zip(X,Y))/len(X)
theta = [theta0, theta1]

1 个答案:

答案 0 :(得分:0)

学习率太高了。

alpha = 0.0001