r语言 - 我的插入符号"rf"模型中使用了多少棵树?



当在插入符号"rf"模型中未指定ntree计数时,我很难找到模型中使用了多少棵树。

以下是我用来训练模型的代码:

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")

使用 print(rf_model_down) 函数,我能够看到mtry是什么,但它没有告诉我们使用的ntree计数。

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.
提前感谢我很难

找到的很可能是一个简单的答案......

检查str(rf_model_down)表明我们可以使用

rf_model_down$finalModel$ntree

最新更新