Error in R gbm function when cv.folds> 0

I use gbm to predict binary response. When I set cv.folds = 0, everything works fine. However, when cv.folds> 1, I got the error: Error in object$var.levels[[i]] : subscript out of bounds when the first cross validation irritation ended. Someone said that this is possible because some factor variables have missing levels in training or testing data, but I tried using only 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 any ideas on this? Thanks!

Answer yourself: The problem is solved. This is due to an error in this function. Input data cannot contain variables other than variables in the model.

+5
source share
1 answer

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

+9
source

Source: https://habr.com/ru/post/1201183/


All Articles