只需输入model_nn 即可为您提供训练期间使用的不同设置的 AUC 分数;这是一个示例,使用iris 数据的前 100 条记录(2 类):
library(caret)
library(nnet)
data(iris)
iris_reduced <- iris[1:100,]
iris_reduced <- droplevels(iris_reduced, "virginica")
model_nn <- train(
Species ~ ., iris_reduced,
method = "nnet",
metric = "ROC",
trControl = trainControl(
method = "cv",
number = 5,
verboseIter = TRUE,
classProbs = TRUE,
summaryFunction = twoClassSummary
)
)
model_nn
结果:
Neural Network
100 samples
4 predictors
2 classes: 'setosa', 'versicolor'
No pre-processing
Resampling: Cross-Validated (5 fold)
Summary of sample sizes: 80, 80, 80, 80, 80
Resampling results across tuning parameters:
size decay ROC Sens Spec
1 0e+00 1.0 1.0 1
1 1e-04 0.8 0.8 1
1 1e-01 1.0 1.0 1
3 0e+00 1.0 1.0 1
3 1e-04 1.0 1.0 1
3 1e-01 1.0 1.0 1
5 0e+00 1.0 1.0 1
5 1e-04 1.0 1.0 1
5 1e-01 1.0 1.0 1
ROC was used to select the optimal model using the largest value.
The final values used for the model were size = 1 and decay = 0.1.
顺便说一句,这里的“ROC”一词有些误导:返回的当然不是 ROC(这是一个 曲线,而不是数字),而是 ROC 曲线下的面积,即AUC(在trainControl中使用metric='AUC'具有相同的效果)。