xgboost的github仓库中自定义目标函数示例脚本中如何计算对数损失的梯度和黑塞矩阵?

我想了解xgboost示例脚本中对数损失函数的梯度和黑塞矩阵是如何计算的,该脚本可以在这里找到。

我已经简化了函数以接受numpy数组,并生成了y_haty_true,它们是脚本中使用的值的样本。

这是一个简化的示例:

import numpy as npdef 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, hessy_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

这些方程是如何相等的?


回答:

对数损失函数给出如下:

enter image description here

其中

enter image description here

通过求偏导数,我们得到梯度为

enter image description here

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

可以进行类似的计算来获得黑塞矩阵。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注