I'm able to parallelize randomForest
based on the foreach
function in the following way:
model_rf <- foreach(ntree=rep(250, 4), .combine=combine, .multicombine=TRUE, .packages='randomForest') %dopar%
randomForest(x = as.matrix(x.train), y = y.train, ntree=ntree, mtry = floor(ncol(x.train)/3))
prediction_rf <- predict(model_rf, x.test)
But trying to do the same thing with gbm
(like below) does not work:
model_gbm <- foreach(ntree=rep(1250, 4), .combine=combine, .multicombine=TRUE, .packages='gbm') %dopar%
gbm.fit(x = as.matrix(x.train), y = y.train, distribution = "gaussian", n.trees = ntree, interaction.depth = 1, verbose = F)
prediction_gbm <- predict(model_gbm, x.test, n.trees = 5000)
This throws out the following error:
error calling combine function:
<simpleError in fun(result.1, result.2, result.3, result.4): Argument must be a list of randomForest objects>
What is the right way to combine and predict with gbm?
P.S.
I also tried using the gbm
function with n.cores=4
instead of the gbm.fit
function, but I got the following error:
Error: protect(): protection stack overflow
combine
function that you are attempting to use to combinegbm
objects is? $\endgroup$