XGBoost列车阶段错误

时间:2017-02-19 04:16:35

标签: r machine-learning data-manipulation xgboost

我有一个数据集并尝试使用XGBoost

我收到以下错误

xgb.trani.matrix = xgb.DMatrix(data=data.matrix(train.xgboost))

Error in xgb.DMatrix(data = data.matrix(train.xgboost)) : 
REAL() can only be applied to a 'numeric', not a 'list'

我使用此

将我的int功能转换为数字功能
train.xgboost <- lapply(train.xgboost, as.numeric)

并检查了数据类型,它显示了[所有功能在转换之后看起来是数字]: -

  

STR(train.xgboost)

List of 708
 $ V13 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V14 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V15 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V16 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V33 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V34 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V35 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V36 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V37 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V38 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V39 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V40 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V41 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V42 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V43 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V44 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V45 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V46 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V47 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V48 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V49 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V50 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V51 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V52 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V59 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V61 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V62 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V63 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V64 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V65 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V66 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V67 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V68 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V69 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V70 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V71 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V72 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V73 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V74 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V75 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V76 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V77 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V78 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V79 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V80 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V81 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V82 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V87 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V88 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V89 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V90 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V91 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V92 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V93 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V94 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V95 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V96 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V97 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V98 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V99 : num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V100: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V101: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V102: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V103: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V104: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V105: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V106: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V107: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V108: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V109: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V110: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V111: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V114: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V115: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V116: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V117: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V118: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V119: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V120: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V121: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V122: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V123: num [1:36082] 0 0 0 0 8 0 0 0 0 0 ...
 $ V124: num [1:36082] 0 0 0 0 76 0 0 0 0 0 ...
 $ V125: num [1:36082] 0 0 0 0 202 0 0 0 0 0 ...
 $ V126: num [1:36082] 0 0 0 0 254 0 0 0 0 0 ...
 $ V127: num [1:36082] 0 0 0 0 255 0 28 0 42 0 ...
 $ V128: num [1:36082] 51 0 0 0 163 0 164 0 235 0 ...
 $ V129: num [1:36082] 159 0 0 0 37 0 254 105 255 0 ...
 $ V130: num [1:36082] 253 64 0 0 2 0 233 255 84 0 ...
 $ V131: num [1:36082] 159 253 0 0 0 0 148 219 0 0 ...
 $ V132: num [1:36082] 50 255 0 0 0 0 11 67 0 0 ...
 $ V133: num [1:36082] 0 63 0 0 0 0 0 67 0 0 ...
 $ V134: num [1:36082] 0 0 0 0 0 0 0 52 0 0 ...
 $ V135: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V136: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V137: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V138: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V139: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
 $ V143: num [1:36082] 0 0 0 0 0 0 0 0 0 0 ...
  [list output truncated]

我无法理解,因为所有功能都是数字,那么为什么XGBoost会出现上述错误。

请建议。

1 个答案:

答案 0 :(得分:0)

我想你可能想尝试一下:

xgb.train.matrix = xgb.DMatrix(data=data.matrix(train.xgboost))

为了看到这一点,我创建了一些模拟数据:

first = list(a = 1, b = 2, c = 3)
second = list(a = 2, b = 3, c = 4)
d<-Map(c,first,second)

d看起来像你的对象:

> str(d)
List of 3
 $ a: num [1:2] 1 2
 $ b: num [1:2] 2 3
 $ c: num [1:2] 3 4

现在,如果你这样做:

> data.matrix(d)
  [,1]     
a Numeric,2
b Numeric,2
c Numeric,2

如果按照我的建议,这是不需要的Vs:

> data.matrix(as.data.frame(d))
     a b c
[1,] 1 2 3
[2,] 2 3 4