0
$\begingroup$

I am using the caret package and need to train a random forest, where only certain samples should be in the held-out set. I want to define the sampling for each tree in the random forest, for say 100 tress. How can I do this? What does the number of re-sample iteration even mean (is it the same as the number of trees)?

I have tried the following but for some reason it is taking an unusual long time to train, so I am not certain whether it is correct or not:

library(caret)
temp.resample_in <- createResample(training_index, times=100)  
temp.resample_out <- foreach (temp.ind = 1:length(temp.resample_in) {
   setdiff(training_index, temp.resample_in[[temp.ind]])
}

fitControl <- trainControl(
method = "oob",
number = 100,
classProbs = TRUE,         
allowParallel = TRUE,
summaryFunction = twoClassSummary,
index = temp.resample_in, 
indexOut = temp.resample_out) 

rf.model <- train(x = data, method = "rf"
                ,  trControl = fitControl                   
                , verbose = TRUE
                , metric = "ROC")
$\endgroup$

closed as off-topic by kjetil b halvorsen, Michael Chernick, mkt - Reinstate Monica, Robert Long, Peter Flom - Reinstate Monica Oct 8 at 9:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – kjetil b halvorsen, Michael Chernick, mkt - Reinstate Monica, Robert Long, Peter Flom - Reinstate Monica
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$

only certain samples should be in the held-out set

The held-out set inside of random forest? I don't think you can do that.

trainControl can let you specify what gets held out when you use cross-validation or bootstrapping (but the bootstrapping outside of random forests). You are using method = "oob" so you aren't intending on doing any external resampling but since you use index it probably is doing 100 iterations (which is why it is taking so long).

You would need to interact directly with the randomForest function but I don't think it give you that level of control.

Max

$\endgroup$

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