如何在插入符号中重复创建分层折叠?

时间:2016-08-24 18:18:10

标签: machine-learning r-caret cross-validation

在插入符号中为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,折叠索引的创建基于&#34; group&#34;变量。

但是,有没有办法在插入符号中重复创建文件?因此,我可以对重复进行平衡分割。我应该组合几个createFolds并运行trainControl吗?

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

谢谢!

1 个答案:

答案 0 :(得分:0)

createMultiFolds可能是你感兴趣的。