我的插入符 "rf" 模型中使用了多少棵树?
How many trees were used in my caret "rf" model?
当没有在插入符号 "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
当没有在插入符号 "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