我的问题与插入符号中提出的问题非常相似 :结合 createResample 和 groupKFold
唯一的区别:我需要在分组后创建分层折叠(也重复 10 次)而不是自举重采样(据我所知没有分层),以便将它与插入符号的 trainControl 一起使用。以下代码使用 10 倍重复的 CV,但我无法包含基于“ID” ( df$ID)的数据分组。
# creating indices
cv.10.folds <- createMultiFolds(rf_label, k = 10, times = 10)
# creating folds
ctrl.10fold <- trainControl(method = "repeatedcv", number = 10, repeats = 10, index = cv.10.folds)
# train
rf.ctrl10 <- train(rf_train, y = rf_label, method = "rf", tuneLength = 6,
ntree = 1000, trControl = ctrl.10fold, importance = TRUE)
Run Code Online (Sandbox Code Playgroud)
这是我的实际问题:我的数据包含许多组,每个组由 20 个实例组成,具有相同的“ID”。因此,当使用 10 倍 CV 重复 10 次时,我在训练中得到了一组实例,在验证集中得到了一些实例。我想避免这种情况,但总的来说,我需要对预测值 ( …