如何在插入符号中为 repeatedcv 创建分层折叠?

How to create stratified folds for repeatedcv in caret?

在插入符号中为 cv 创建分层折叠的方法是这样的

library(caret)
library(data.table)
train_dat <- data.table(group = c(rep("group1",10), rep("group2",5)), x1 = rnorm(15), x2 = rnorm(15), label = factor(c(rep("treatment",15), rep("control",15))))

folds <- createFolds(train_dat[, group], k = 5)

fitCtrl <- trainControl(method = "cv", index = folds, classProbs = T, summaryFunction = twoClassSummary)
train(label~., data = train_dat[, !c("group"), with = F], trControl = fitCtrl, method = "xgbTree", metric = "ROC")

为了平衡group1和group2,折叠索引的创建基于"group"变量。

但是,有没有办法为插入符号中的 repeatedcv 创建折叠?所以,我可以对 repeatedcv 进行平衡拆分。我应该组合几个 createFolds 和 运行 trainControl 吗?

trControl = trainControl(method = "cv", index = many_repeated_folds) 

谢谢!

createMultiFolds 可能是您感兴趣的内容。