2
$\begingroup$

I have a dataset with 1205 observations and 285 predictors (all but one categorical). It is a binary classification task.

  • When I run randomForest, it executes in less than 1 second.
  • When I run caret with method = "none" in trControl, it executes in 81 seconds
  • When I run caret with method = "boot" in trControl (number = 1), it executes in 158 seconds

So what is being done extra in caret that makes such a big difference in execution times? Note that I included method = "none", which I think is supposed to prevent resampling. (I even looked in the caret source code...)

Here is my code:

rfControl <- trainControl(method = "boot", number = 1, repeats = 1)
rfControl2 <- trainControl(method = "none", number = 1, repeats = 1)
rfGrid <- expand.grid(mtry = c(16))

system.time( train( labelidx ~ ., data = t, method = "rf", ntree = 100, 
                    trControl = rfControl2, tuneGrid = rfGrid))

library(randomForest)
system.time( randomForest(labelidx ~ ., data = t, ntree = 100, mtry = 16))

and here are the results, pasted from rstudio:

> system.time( train( labelidx ~ ., data = t, method = "rf", ntree = 100, 
+                     trControl = rfControl, tuneGrid = rfGrid))
   user  system elapsed 
158.203   0.039 158.299 
> system.time( train( labelidx ~ ., data = t, method = "rf", ntree = 100, 
+                     trControl = rfControl2, tuneGrid = rfGrid))
   user  system elapsed 
 81.385   0.012  81.442 
> c(rfControl$method, rfControl$number, rfControl$repeats)
    [1] "boot" "1"    "1"   
    > c(rfControl2$method, rfControl2$number, rfControl2$repeats)
[1] "none" "1"    "1"   
> rfGrid
  mtry
1   16
> c(nrow(t), ncol(t))
[1] 1205  286

> system.time( randomForest(labelidx ~ ., data = t, ntree = 100, mtry = 16))
   user  system elapsed 
  0.354   0.000   0.354 
$\endgroup$
  • 1
    $\begingroup$ This post should probably be migrated over to StackOverflow. $\endgroup$ – Steve S Jan 10 '16 at 23:47
  • $\begingroup$ It would be easier to help you if you included a reproducible example. $\endgroup$ – Johan Larsson Mar 9 '16 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.