`caret` 中的训练错误率

Training error rate in `caret`

我不知道如何使用 R 中的 caret 包提取训练误差(即在训练集上获得的误差)。例如,我有以下模型:

data(iris);
library(caret);
model<-train(Species~., data=iris, method='knn', trControl=trainControl(method='cv', number=10), tuneGrid=data.frame(k=20))

我想做的是查看模型在训练数据上的表现如何。

我知道我可以使用 model$results 获得每次折叠在测试集上的性能,但这不是我想要的。我想展示训练错误如何 way 过于乐观,但我做不到。此处的文档:

http://www.inside-r.org/packages/cran/caret/docs/train

表示

results: a data frame the training error rate and values of the tuning parameters.

不是,因为在我的例子中,model$results$Accuracy总是正好等于mean(model$resample$Accuracy)。这是 testing 错误率的值。我想要 training 错误率。有办法得到吗?

我想你是在问这样的事情:

model3<-train(Species~., data=iris, method='knn', trControl=trainControl(method='none'), tuneGrid=data.frame(k=20))
testPred <- predict(model3, iris)
postResample(testPred, iris$Species)

Accuracy    Kappa 
    0.98     0.97