首页 > 解决方案 > 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))
}

但我似乎无法弄清楚如何做到这一点,有什么建议吗?

标签: rxgboost

解决方案


推荐阅读