【问题标题】:Error in R gbm function when cv.folds > 0当 cv.folds > 0 时,R gbm 函数出错
【发布时间】:2014-10-20 06:57:56
【问题描述】:

我正在使用 gbm 来预测二进制响应。 当我设置 cv.folds=0 时,一切正常。但是,当 cv.folds > 1 时,当交叉验证的第一次刺激完成时,我得到错误:Error in object$var.levels[[i]] : subscript out of bounds。有人说这可能是因为某些因子变量在训练或测试数据中缺少水平,但我尝试只使用数字变量仍然会出现此错误。

> gbm.fit <- gbm(model.formula,
+                data=dataall_train,
+                distribution = "adaboost",
+                n.trees=10,
+                shrinkage=0.05,
+                interaction.depth=2,
+                bag.fraction = 0.5,
+                n.minobsinnode = 10,      
+                train.fraction=0.5,
+                cv.folds=3,
+                verbose=T,
+                n.cores=1)
CV: 1 
CV: 2 
CV: 3 
Error in object$var.levels[[i]] : subscript out of bounds

有人对此有一些见解吗?谢谢!

回答我自己: 问题解决了。这是因为这个函数中的一个错误。输入数据不能包含模型中变量以外的变量。

【问题讨论】:

  • 这可能是您的数据。没有它,我们前进的速度会很慢。
  • 我在使用 caret R 包时遇到了同样的问题,随后使用包作者的以下建议:github.com/topepo/caret/issues/330

标签: r gbm


【解决方案1】:

我支持这个解决方案:R 函数 gbm() 中的输入数据不能包含不会在您的模型中使用的变量(列)。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-06-22
  • 1970-01-01
  • 2016-01-22
  • 2019-10-25
  • 2017-03-18
  • 2013-10-28
  • 1970-01-01
相关资源
最近更新 更多