交叉熵损失函数(Cross_entropy loss)的梯度下降法中w和b的梯度问题
作者:互联网
# 计算梯度值(?)
def gradient(X, Y_label, w, b):
# This function computes the gradient of cross entropy loss with respect to weight w and bias b.
y_pred = forward(X, w, b)
pred_error = Y_label - y_pred
w_grad = -np.sum(pred_error * X.T, 1)
b_grad = -np.sum(pred_error)
return w_grad, b_grad
推导如下:
标签:loss,gradient,梯度,Cross,entropy,error,grad,pred 来源: https://blog.csdn.net/weixin_42869502/article/details/115534546