0
$\begingroup$

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
$\endgroup$
3
  • 1
    $\begingroup$ Do you know what the combine function that you are attempting to use to combine gbm objects is? $\endgroup$ Jan 8, 2016 at 20:54
  • $\begingroup$ @MatthewDrury It's the one used for combining trees from randomForest. I'm trying to reuse the same for gbm. $\endgroup$
    – Arjun
    Jan 9, 2016 at 19:33
  • $\begingroup$ How do you think the one for combining forests works? $\endgroup$ Jan 9, 2016 at 23:33

2 Answers 2

5
$\begingroup$

GBM is an inherently sequential algorithm. Each iteration depends on the results of the previous iteration. Contrast this with Random Forest where the algorithm is embarrassingly parallel -- every tree is independent of each other. This allows RF to be parallelized in ways GBM cannot.

The combine function you are using is from the randomForest package and it is crafted to specifically work on randomForest objects, as the error message says.

In summary you are trying to parallelize an inherently sequential algorithm and then combine the results using a function meant to concatenate independent randomForests.

If you're looking for performance gains for GBM models, check out the xgboost package. Parts of GBM can be parallel, such as the construction of the decision trees. This is the approach xgboost takes.

$\endgroup$
2
$\begingroup$

As other people have pointed out, you cannot combine multiple gbm models as it is not an ensemble learning technique like randomForest.

However, the challenge in GBM is hyper parameter optimisation( finding the parameters that yield the best results ). This can parallelised easily with the help of big data system.

$\endgroup$
2
  • $\begingroup$ Possibly, you could expand somewhat your answer. $\endgroup$ Jun 14, 2016 at 11:28
  • $\begingroup$ You can create a grid of hyper-parameters (learning rate, depth, min obs in nodes, etc...) and build a full model on each combination of parameters in parallel. The foreach package works great for such problems and I believe caret provides it as well although I prefer to roll my own. $\endgroup$
    – Zelazny7
    Jun 14, 2016 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.