RepeatedKFold实际上意味着什么?

时间:2018-02-28 13:14:37

标签: python machine-learning scikit-learn data-science cross-validation

n_repeats=5,折叠数为3(n_splits=3)。

这是否意味着验证器为我们的估算器/模型创建了3倍以使用每个折叠(如KFold的用途),然后重复该过程5次?

这意味着我们的模型将总共使用5 x 3 = 15倍?

1 个答案:

答案 0 :(得分:3)

是的,通过在循环中调用KFolds.split() n_repeats次,基本上可以达到相同的效果。

示例设置:

X = np.array([[1, 2], [3, 4], [1, 2], [3, 4]])
y = np.array([0, 0, 1, 1])

然后跑步:

rkf = RepeatedKFold(n_splits=2, n_repeats=1, random_state=2652124)
for train_index, test_index in rkf.split(X):
  print("TRAIN:", train_index, "TEST:", test_index)

...生产:

TRAIN: [0 1] TEST: [2 3]
TRAIN: [2 3] TEST: [0 1]

...就像KFold(n_splits=2, random_state=2652124)一样。更改为n_repeats=2会产生:

TRAIN: [0 1] TEST: [2 3]
TRAIN: [2 3] TEST: [0 1]
TRAIN: [1 2] TEST: [0 3]
TRAIN: [0 3] TEST: [1 2]

等等。