在插入符号“ 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.
在此先感谢我最难找到答案的简单答案...
答案 0 :(得分:2)
检查str(rf_model_down)
表明我们可以使用
rf_model_down$finalModel$ntree