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

发布于 2025-01-11 23:00:39 字数 681 浏览 1 评论 0原文

我想评估我创建的逻辑回归模型是否过度拟合。我想将每个训练折叠的准确性与测试折叠进行比较,但我不知道如何在 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

How do I view the Training Accuracy of every Fold ?

I would like to evaluate whether the logistic regression model I created is overfit. I'd like to compare the accuracies of each training fold to the test fold, but I don't know how to view these in R. This is the k-fold cross validation code:

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

How do I view the training accuracies of each fold?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-01-18 23:00:39

查看 model1$resample - 它应该为您提供一个包含每次折叠的准确度(和 Kappa)的表格。

Look at model1$resample - it should give you a table with Accuracy (and Kappa) for each fold.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文