jasonlcy91
jasonlcy91

Reputation: 464

What does RepeatedKFold actually mean?

Say n_repeats=5 and the number of fold is 3 (n_splits=3).

Does that mean the validator is creating 3-folds for our estimator/model to use every fold (like what KFold is for), then repeating that process for 5 times?

That means our model will use a total of 5 x 3 = 15 folds?

Upvotes: 8

Views: 5586

Answers (1)

Maxim
Maxim

Reputation: 53758

Yes, you can basically achieve the same effect by calling KFolds.split() n_repeats times in a loop.

Example setup:

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

Then running:

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)

... produces:

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

... just like KFold(n_splits=2, random_state=2652124) would. Changing to n_repeats=2 produces:

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

And so on.

Upvotes: 10

Related Questions