我需要在自定义评估函数上优化xgboost参数。 但是,为此,我需要加入有关所选观察值的其他一些信息来衡量性能。
对我来说最好的方法是将信息直接添加到xgb.DMatrix中,例如:
dtrain <- xgb.DMatrix(data = matrix,label = OBSERVATIONS$actual,ID = OBSERVATIONS$ID)
这样,我将能够检索正在评估的观察结果,并加入一些附加信息进行评估。 像这样:
feval = function(preds,dtrain){
# getting labels
actual <- getinfo(dtrain,"label")
# Retrieving additionnal information
ID <- getinfo(dtrain,"ID")
dt <- data.table(ID = ID,actual = actual,preds = preds)
# Note that it would work also work if there is a way to know what
# is the index of the observations in dtrain
# Joining additional information
dt = scalingFact[dt,on = c("ID")]
任何人都知道我是否可以通过索引或将我可能需要的其他信息添加到矩阵中?