Skip to content

Instantly share code, notes, and snippets.

@zachmayer
Created May 10, 2013 13:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachmayer/5554373 to your computer and use it in GitHub Desktop.
Save zachmayer/5554373 to your computer and use it in GitHub Desktop.
A better multiRFfunction
multiRF <- function(X, Y, mtry_vector,...) {
stopifnot(require(doRNG))
stopifnot(require(randomForest))
stopifnot(is.numeric(mtry_vector))
stopifnot(all(mtry_vector>1))
foreach(i=mtry_vector,.combine=randomForest::combine,.packages='randomForest',.export=c('X','Y'),.inorder=FALSE) %dorng% {
randomForest(X,Y,mtry=i,...)
}
}
library(doParallel)
data(iris)
a <- c(rep(3,10),rep(4,10),rep(5,10))
registerDoParallel(cores=1)
system.time(output<-multiRF(iris[,-5], iris[,5], a, ntree=500))
registerDoParallel(cores=8)
system.time(output<-multiRF(iris[,-5], iris[,5], a, ntree=500))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment