def gradient(train,
labels,
coef,
bias,
learn_rate,
nepoch):
for epoch in range(nepoch):
sum_error = 0.0
for index in range(len(train)):
pred = predict(train[index], coef, bias)
sum_error += (labels[index] - pred)
bias = (bias + learn_rate * sum_error * pred * (1 - pred))
for i in range(len(coef)):
coef[i] = (coef[i] + learn_rate * sum_error * pred * (1 - pred) * train[index][i])
return coef, bias
#generate standard normal distribution
#TODO the function random.gauss() can not generate stable distribution which causes diffusion gradient
评论列表
文章目录