python - 客观论点在 python 的 xgboost 中是如何工作的?
问题描述
梯度提升树可以采用自定义目标函数。这很棒,因为对于我的特定任务,我有一个非常具体的损失函数,我可以计算关于预测的一阶和二阶导数。
需要明确的是,通常机器学习任务的目标函数通常定义为 obj = 损失 + 复杂度。
但是,我想保持由 给出的标准复杂性惩罚Omega(f) = gamma*T + (1/2)*lambda * \sum_{j=1}^T(w^2_j)
不变。这里,T,gamma,lambda,w
分别是树中叶子的数量、在树的叶子节点上进行进一步分区所需的最小损失减少、权重的 L2 正则化项和每个叶子的权重向量。
我的问题是,使用xgboost 的标准 python 实现,我可以只定义损失函数作为objective
参数的输入,并让 xgboost 库处理复杂性项吗?这会很棒,因为我不想更改复杂度项或计算它的导数。
我的猜测是,不幸的是,我们还必须定义复杂度项,因为根据定义,目标函数是损失和复杂度的线性组合。
注意:如果我们查看 XGBClassifier 的注释
from xgboost import XGBClassifier
help(XGBClassifier)
...
| objective : string or callable
| Specify the learning task and the corresponding learning objective or
| a custom objective function to be used (see note below).
...
...
| Note
| ----
| A custom objective function can be provided for the ``objective``
| parameter. In this case, it should have the signature
| ``objective(y_true, y_pred) -> grad, hess``:
|
| y_true: array_like of shape [n_samples]
| The target values
| y_pred: array_like of shape [n_samples]
| The predicted values
|
| grad: array_like of shape [n_samples]
| The value of the gradient for each sample point.
| hess: array_like of shape [n_samples]
| The value of the second derivative for each sample point
我们看到自定义objective
函数的唯一输入应该是y_pred
and y_true
。所以我不明白,如果我们确实需要定义复杂性术语,复杂性参数 ( T,gamma,lambda,w
) 将如何在自定义目标函数中定义。
解决方案
推荐阅读
- javascript - “找不到变量”与“未定义”之间的区别
- java - 如何调用使用 GCP 身份验证的 REST 服务?
- css - SASS:选择最近的
- zebra-printers - 如何使用 Google 云打印将 ZPL 发送到 Zebra?
- javascript - Gatsby TypeError:无法读取未定义的属性“allWordpressAcfOptions”
- .net - 使用 SignalR azure 服务在 2 个 Angular 应用程序之间进行通信
- microsoft-graph-api - 如何将 InternetMessageHeaders 添加到回复消息
- android - 即使授予权限,checkSelfPermission 也会返回 false
- python - 如图所示,如何格式化这个乘法表?
- java - 为什么我在 AWS Cloud9 中运行的 java spring 项目运行一段时间后关闭?