为什么我得到:在将 mlr 与 xgboost 一起使用时,标签的长度必须等于输入数据错误中的行数

Why do I get: The length of labels must equal the number of rows in the input data error while using mlr with xgboost

在运行之后的R代码如下:

#' load libraries
library(parallelMap)
library(mlr)

#' *** Define the task
task = makeClassifTask(id = "classif_prem", 
                       data = data, 
                       target = "Result")

#' *** Define the learner
lrn = makeLearner(id = "learn_prem", cl = "classif.xgboost")

#' train model
mod = train(learner = lrn, task = task)

在 运行 str(data) 之后我得到:

> str(data)
Classes ‘tbl_df’ and 'data.frame':  210 obs. of  3 variables:
 $ Result  : Factor w/ 3 levels "Draw","Loss",..: 1 3 1 1 1 2 2 2 1 1 ...
 $ RankDiff: int  11 3 11 5 -14 11 -2 -4 5 -8 ...
 $ DiffDiff: num  1.5 -1 1.5 -1 -1 0 0 -1.5 0 -1.5 ...

任务摘要给出:

Supervised task: classif_prem
Type: classif
Target: Result
Observations: 210
Features:
numerics  factors  ordered 
       2        0        0 
Missings: FALSE
Has weights: FALSE
Has blocking: FALSE
Classes: 3
Draw Loss  Win 
  61   64   85 
Positive class: NA
Warning message:
drop ignored 

然后我得到错误:

Error in xgb.setinfo(dmat, names(p), p[[1]]) : 
The length of labels must equal to the number of rows in the input data
In addition: Warning message:
drop ignored 

如能帮助我避免此错误,我们将不胜感激。谢谢

非常感谢。额外的 tbl_df class 混淆了 mlr 和 xgboost。我只做了一个 data.frame 就成功了。