正如标题所说,我想知道 sklearnGroupKFold
和GroupShuffleSplit
.
两者都为具有组 ID 的数据进行训练测试拆分,因此这些组不会在拆分中分离。我检查了每个函数的一个训练集/测试集,它们看起来都做了一个很好的分层,但如果有人能确认所有拆分都这样做,那就太好了。
我对两者进行了测试,分为 10 次:
gss = GroupShuffleSplit(n_splits=10, train_size=0.8, random_state=42)
for train_idx, test_idx in gss.split(X,y,groups):
print("train:", train_idx, "test:", test_idx)
train: [ 1 2 3 4 5 11 12 13 14 15 16 17 19 20] test: [ 0 6 7 8 9 10 18]
train: [ 1 2 3 4 5 6 7 8 9 10 12 13 14 18 19 20] test: [ 0 11 15 16 17]
train: [ 0 1 3 4 5 6 7 8 9 10 12 13 14 18 19 20] test: [ 2 11 15 16 17]
train: [ 0 2 3 4 11 12 13 14 15 16 17 18 19 20] test: [ 1 5 6 7 8 9 10]
train: [ 0 1 3 4 5 6 7 8 9 10 11 15 16 17 19 20] test: [ 2 12 13 14 18]
train: [ 1 2 3 4 5 6 7 8 9 10 11 15 16 17 18] test: [ 0 12 13 14 19 20]
train: [ 0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17] test: [ 5 18 19 20]
train: [ 0 1 3 4 6 7 8 9 10 11 15 16 17 18 19 20] test: [ 2 5 12 13 14]
train: [ 0 1 3 4 5 12 13 14 15 16 17 18 19 20] test: [ 2 6 7 8 9 10 11]
train: [ 0 2 3 4 5 11 12 13 14 15 16 17 19 20] test: [ 1 6 7 8 9 10 18]
group_kfold = GroupKFold(n_splits=10)
for train_idx, test_idx in group_kfold.split(X,y,groups):
print("train:", train_idx, "test:", test_idx)
train: [ 0 1 2 3 4 5 11 12 13 14 15 16 17 18 19 20] test: [ 6 7 8 9 10]
train: [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 18 19 20] test: [15 16 17]
train: [ 0 1 2 3 4 5 6 7 8 9 10 11 15 16 17 18 19 20] test: [12 13 14]
train: [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18] test: [19 20]
train: [ 0 1 2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] test: [3 4]
train: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20] test: [ 0 18]
train: [ 0 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20] test: [11]
train: [ 0 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] test: [5]
train: [ 0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] test: [2]
train: [ 0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] test: [1]