我正在使用caret的twoClassSummary函数来确定最优模型超参数以最大化“特异性”。然而,该函数如何确定最大化“特异性”的概率阈值呢?在每个模型超参数/折叠中,caret是否会评估0到1之间的每个阈值,并返回最大“特异性”?在下面的示例中,您可以看到该模型已落在cp = 0.01492537上。
# load libraries
library(caret)
library(mlbench)
# load the dataset
data(PimaIndiansDiabetes)
# prepare resampling method
control <- trainControl(method="cv",
number=5,
classProbs=TRUE,
summaryFunction=twoClassSummary)
set.seed(7)
fit <- train(diabetes~.,
data=PimaIndiansDiabetes,
method="rpart",
tuneLength= 5,
metric="Spec",
trControl=control)
print(fit)
CART
768 samples
8 predictor
2 classes: 'neg', 'pos'
No pre-processing
Resampling: Cross-Validated (5 fold)
Summary of sample sizes: 614, 614, 615, 615, 614
Resampling results across tuning parameters:
cp ROC Sens Spec
0.01305970 0.7615943 0.824 0.5937806
0.01492537 0.7712055 0.824 0.6016073
0.01741294 0.7544469 0.830 0.5976939
0.10447761 0.6915783 0.866 0.5035639
0.24253731 0.6437820 0.884 0.4035639
Spec was used to select the optimal model using the largest value.
The final value used for the model was cp = 0.01492537.