Error in R gbm function when cv.folds > 0

梦想的初衷 提交于 2020-01-10 15:41:11

问题


I am using gbm to predict binary response. When I set cv.folds=0, everything works well. 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. 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.


回答1:


I second this solution: The input data in the R function gbm() cannot include the variables (columns) that will not be used in your model.



来源:https://stackoverflow.com/questions/25514484/error-in-r-gbm-function-when-cv-folds-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!