bshelt141
bshelt141

Reputation: 1223

How many trees were used in my caret "rf" model?

When not specifying the ntree count in a caret "rf" model, I am having a difficult time finding how many trees were used in the model.

Here is the code I am using to train my model:

fitControl <- trainControl(
    method = "cv",                     
    number = 3,                        
    savePredictions = "final",         
    classProbs = T,                   
    summaryFunction = twoClassSummary, 
    sampling = "down")                 

set.seed(3219)
  rf_model_down <- train(Class ~ .,
                         data = train_data,
                         method ='rf',
                         tuneLength = 2,
                         trControl = fitControl,
                         metric = "ROC")

using the print(rf_model_down) function, I am able to see what the mtry was, but it doesn't tell us the ntree count used.

print(rf_model_down)

# Random Forest 
#
# 10000 samples
#    94 predictor
#     2 classes: 'Fraud', 'notFraud' 
#
# No pre-processing
# Resampling: Cross-Validated (3 fold) 
# Summary of sample sizes: 6667, 6666, 6667 
# Addtional sampling using down-sampling
#
# Resampling results across tuning parameters:
#
#   mtry  ROC        Sens       Spec     
#    2    0.7401603  0.7691257  0.5717070
#   94    0.7449104  0.6814208  0.6641911
#
# ROC was used to select the optimal model using the largest value.
# The final value used for the model was mtry = 94.

Thanks, in advance, for what is most likely an easy answer that I'm having a difficult time finding...

Upvotes: 2

Views: 785

Answers (1)

Julius Vainora
Julius Vainora

Reputation: 48201

Inspecting str(rf_model_down) shows that we can use

rf_model_down$finalModel$ntree

Upvotes: 3

Related Questions