虽然这已经得到解答,但如果您想要一些代码允许您在插入符号中使用相同的 CV 拆分进行多个模型训练,您可以使用以下代码:
tune_control <- trainControl(
method = "repeatedcv",
repeats = 2,
number = 5,
index = createMultiFolds(df$y, k=5, times=2) # assuming your object is df and you are modeling y
)
您可以通过训练两个模型并比较以下输出来手动检查它是否有效:
model$control$index # replace model w/ name of your model
应该打印出如下内容:
List of 10
Fold1.Rep1: int [1:2400] 1 2 3 4 5 7 9 10 11 12 ...
Fold2.Rep1: int [1:2400] 1 2 3 4 5 6 7 8 9 10 ...
Fold3.Rep1: int [1:2400] 2 3 4 6 8 9 10 11 13 14 ...
Fold4.Rep1: int [1:2400] 1 2 5 6 7 8 11 12 16 18 ...
Fold5.Rep1: int [1:2400] 1 3 4 5 6 7 8 9 10 11 ...
Fold1.Rep2: int [1:2400] 1 3 4 5 6 8 10 11 12 14 ...
Fold2.Rep2: int [1:2400] 1 2 3 4 5 6 7 8 9 10 ...
Fold3.Rep2: int [1:2400] 2 3 4 5 7 8 9 10 11 12 ...
Fold4.Rep2: int [1:2400] 1 2 3 5 6 7 8 9 11 12 ...
Fold5.Rep2: int [1:2400] 1 2 4 6 7 9 10 13 16 17 ...