下面有一段代码,它逐步完成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]
答案 0 :(得分:0)
学习率太高了。
alpha = 0.0001