2

I routinely use the foreach package for training random forests in R, and I'm trying to find a rough equivalent for training adaboost models, but I'm running into the problem of how to combine the results. The randomForest package has the 'combine' function which allows for combining multiple randomForest objects into a single RF object, are there any boosting packages that feature a similar function? I typically use package adabag, but I can't figure out how to combine the outputted models (or if there even is a way). Has anyone tried this and figured out a solution? This snippet works to create the models in parallel:

library(foreach)
library(adabag)
library(doMC)
library(rpart)

registerDoMC(4)

data(iris)

testADA <- foreach(mfinal = rep(5, 4), .combine = c, .packages = "adabag") %dopar% boosting(Species ~ ., data = iris, boos = TRUE, mfinal = mfinal, control = c(minsplit = 0, cp = 0.000001))

But then I just end up with a list of models rather than a single model and I can't figure out how to combine them.

TomR
  • 546
  • 8
  • 19

1 Answers1

4

You could use caret package. The examples could be find here - http://caret.r-forge.r-project.org/parallel.html.

In your case it could look like that:

library(caret)
library(doMC)
registerDoMC(cores = 4)
model <- train(Species ~ ., data = iris, method = "ada")

"doMC" package doesn't work on Windows. Alternatively, here is solution for Windows machines:

library('doParallel')
cl <- makeCluster(4) #number of cores
registerDoParallel(cl)
model <- train(Species ~ ., data = iris, method = "ada")
stopCluster(cl)
Jot eN
  • 6,120
  • 4
  • 40
  • 59
  • package "doMC" doesn't support R 3.2. Is there anyother way to make caret in parallel? – Cina Jun 19 '15 at 03:31
  • 1
    Cina, I've tried to install "doMC" on R 3.2 and Ubuntu 14.04 and it's working. "doMC" package doesn't work on Windows. I've edited my answer for windows users. – Jot eN Jun 19 '15 at 12:09
  • So does the above code divide your data into 4 equal parts among the 4 cores? – nigus21 Apr 15 '19 at 18:40