如何获得 R 中 k 折交叉验证中每次折叠的训练精度?
我想评估我创建的逻辑回归模型是否过度拟合。我想将每个训练折叠的准确性与测试折叠进行比较,但我不知道如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
model1$resample
- 它应该为您提供一个包含每次折叠的准确度(和 Kappa)的表格。Look at
model1$resample
- it should give you a table with Accuracy (and Kappa) for each fold.