客观的
寻求帮助,请告知为什么梯度下降实现在下面不起作用。
背景
处理以下任务以实现逻辑回归。
梯度下降
如图所示推导出梯度下降。
Typo fixed as in the red in the picture.
交叉熵对数损失为
实现了代码,但是它说不正确。
import numpy as np
def LogitRegression(arr):
# code goes here
x = arr[0]
y = arr[1]
a = arr[2]
b = arr[3]
z = 1.0 / (1.0 + np.exp(-a * x - b))
lr = 1.0
a = a - x * (z-y)
a = np.round(a, decimals=3)
b = b - (z-y)
b = np.round(b, decimals=3)
return ", ".join([str(a), str(b)])
# keep this function call here
print(LogitRegression(input()))
如果我恢复梯度更新的符号,它就可以工作。但是,不知道为什么。
# a = a - x * (z-y)
a = a + x * (z-y)
a = np.round(a, decimals=3)
# b = b - (z-y)
b = b + (z-y)
b = np.round(b, decimals=3)



