Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 357
jasonlcy91 Avatar asked Feb 28 '18 13:02

jasonlcy91


Video Answer


1 Answers

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.

like image 148
Maxim Avatar answered Nov 10 '22 01:11

Maxim