r - Xgboost - 如何制作取决于另一列的值以及错误的自定义损失函数
问题描述
我在为 R 中的 xgboost 训练实施新近加权时遇到问题(即将权重向量传递给 xgb.dmatrix) - 尽管加权会影响训练集的学习曲线读数,但它似乎对实际生产的模型 - 测试集中的性能是相同的。
我似乎无法深入了解这个问题或生成可重现的示例。因此,我想将特征的 Date 列传递给自定义损失函数,例如:
custom_loss <- function(preds,dat) {
labels <- getinfo(dat,"label")
dates <- [a vector corresponding to the dates associated with each prediction]
grad = f(dates)*-2*(labels - preds)
hess = f(dates)*2
[where f is an increasing function of the value in dates, so later samples matter more when training]
return(list(grad=grad,hess=hess))
}
但我似乎无法弄清楚如何做到这一点,有什么建议吗?
解决方案
推荐阅读
- tcl - 我正在尝试执行代码并收到错误“孩子被杀死的分段违规”并且程序停止工作
- python - 嵌套函数调用总是在一起
- vb.net - 我不明白这个 datagridview 新操作调用命令的语法应该是什么
- python - 如何在 Django ORM 中随时间存储数据?
- java - 单个应用程序中的两个身份验证服务
- android - 更新 MACBook Pro 后 Android Studio 自动关闭 - ERROR_CGDataProviderCreateWithData_BufferIsNotReadable+0x10
- c# - 如何从链接下给出的 SharePoint 列表中读取文件内容
- c# - 在 Web api 上正确使用来自同一端点的两个“成功”响应之一的最佳方法是什么?
- discord.py - 我在获取用户在命令后输入的内容时遇到问题
- mysql - SELECT 中的变量赋值评估顺序可能与返回的行顺序不同。在什么条件下会发生这种情况?