简体   繁体   English

cv.folds > 0 时 R gbm 函数出错

[英]Error in R gbm function when cv.folds > 0

I am using gbm to predict binary response.我正在使用 gbm 来预测二元响应。 When I set cv.folds=0, everything works well.当我设置 cv.folds=0 时,一切正常。 However when cv.folds > 1, I got error: Error in object$var.levels[[i]] : subscript out of bounds when the first irritation of crossvalidation finished.但是,当 cv.folds > 1 时,出现错误: Error in object$var.levels[[i]] : subscript out of bounds当交叉验证的第一次刺激完成Error in object$var.levels[[i]] : subscript out of bounds Someone said this could because some factor variables have missing levels in training or testing data, but I tried only use numeric variables and still get this error.有人说这可能是因为某些因子变量在训练或测试数据中缺少水平,但我尝试仅使用数字变量,但仍然出现此错误。

> 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

Anyone have some insights on this?有人对此有一些见解吗? Thanks!谢谢!

Answer my self: Problem solved.回答我自己:问题已解决。 This is because a bug in this function.这是因为这个函数中的一个错误。 The input data cannot contain variables other than the variables in the model.输入数据不能包含模型中的变量以外的变量。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM