问题
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