在xgboost的github代码库中的自定义目标函数示例脚本中,对数损失的梯度和海森矩阵是如何计算的?

7
我希望了解在xgboost示例脚本中,logloss函数的梯度和海森矩阵是如何计算的。我已经简化了函数以使用numpy数组,并生成了y_haty_true,它们是脚本中使用的值的样本。
这是一个简化的示例:
import numpy as np


def loglikelihoodloss(y_hat, y_true):
    prob = 1.0 / (1.0 + np.exp(-y_hat))
    grad = prob - y_true
    hess = prob * (1.0 - prob)
    return grad, hess

y_hat = np.array([1.80087972, -1.82414818, -1.82414818,  1.80087972, -2.08465433,
                  -1.82414818, -1.82414818,  1.80087972, -1.82414818, -1.82414818])
y_true = np.array([1.,  0.,  0.,  1.,  0.,  0.,  0.,  1.,  0.,  0.])

loglikelihoodloss(y_hat, y_true)

对数损失函数是enter image description here的总和,其中enter image description here
然后,对于p,梯度为enter image description here,但在代码中为enter image description here
同样,对于p,二阶导数为enter image description here,但在代码中为enter image description here
这些方程式怎么相等?
1个回答

9

对数损失函数的表达式如下:

enter image description here

其中

enter image description here

对其进行偏导数运算,我们得到梯度为

enter image description here

因此,我们得到负梯度为p-y

类似的计算可以得到海森矩阵。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接