我使用此代码来训练用于4-NN和5-NN的K-NN模型:
trainParameters <- trainControl(method = "repeatedcv", number = 10,
repeats = 1, classProbs = TRUE)
knnModel <- train(Class ~.,
data = trainingSet,
method = "knn",
tuneGrid = expand.grid(k = c(4,5)),
preProcess = c("center","scale"),
trControl = trainParameters)
但是当我执行这一行时:
knnModel
我得到了模型信息,在其中得到了以下消息:
Accuracy was used to select the optimal model using the largest value.
The final value used for the model was k = 5
然后,所有结果(混淆矩阵,指标等)仅与k = 5模型相关。我想让所有模型都包含在c(...)中。我怎样才能得到它们?