如何获得 R 中 k 折交叉验证中每一折的训练精度?

How do I get the training accuracies for each fold in k-fold cross validation in R?

我想评估一下我创建的逻辑回归模型是否过拟合。我想比较每个训练折与测试折的准确性,但我不知道如何在 R 中查看这些。这是 k 折交叉验证代码:

library(caret)
levels(habitatdata$outcome) <- c("absent", "present") #rename factor levels 
set.seed(12)
cvIndex <- createFolds(factor(habitatdata$outcome), 5, returnTrain = T) #create stratified folds
ctrlspecs <- trainControl(index = cvIndex, 
  method = "cv", 
  number = 5, 
  savePredictions = "all", 
  classProbs = TRUE) #specify training methods
set.seed(123)
model1 <- train(outcome~ ist + hwt, 
  data=habitatdata,
  method = "glm",
  family = binomial, trControl = ctrlspecs) #specify model

如何查看每次折叠的训练准确率?

看看 model1$resample - 它应该给你一个 table 每次折叠的准确度(和 Kappa)。