Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Function

RepeatedKFold

RepeatedKFold repeats K-fold cross-validation several times, randomizing the fold assignments for each repetition. Use random_state when reproducible splits are needed.

How it works

RepeatedKFold creates ordinary K-fold train/test partitions multiple times, using a different randomized arrangement for each repetition. Calling split returns index pairs for the training and test portions; setting random_state makes those generated partitions reproducible.

Syntax

class sklearn.model_selection.RepeatedKFold(*, n_splits=5, n_repeats=10, random_state=None)

Parameters

NameTypeDescription
n_splitsintNumber of folds; must be at least 2. Default: 5.
n_repeatsintNumber of times the cross-validator is repeated. Default: 10.
random_stateint, RandomState instance or NoneControls randomization; accepts an int, RandomState instance, or None. Default: None.

Returns

A cross-validator whose split method yields training and test indices for repeated K-fold partitions.

Key points

  • Use it to obtain a cross-validator for repeated K-fold evaluation.
  • Each repetition reruns the folds with a different randomized arrangement.
  • n_splits specifies how many folds each repetition contains.
  • n_repeats specifies how many complete K-fold repetitions are generated.
  • random_state determines the randomization used independently across repeated instances.
  • An integer seed allows repeated calls to produce the same output.

Common mistakes

  • Without a fixed integer random_state, separate split calls can produce different partitions.
  • n_splits cannot be set below two folds.

Example: Generate repeated K-fold splits

import numpy as np
from sklearn.model_selection import RepeatedKFold

X = np.arange(12).reshape(6, 2)
y = np.array([0, 1, 0, 1, 0, 1])
rkf = RepeatedKFold(n_splits=3, n_repeats=2, random_state=42)

for train_idx, test_idx in rkf.split(X, y):
    print(train_idx, test_idx)

Creates six splits: three folds for each of two randomized repetitions.

When to use it

More robust cross-validation estimates

Estimate model performance with less dependence on one fold assignment.

Repeated data splitting

Generate multiple randomized train/test index partitions for repeated evaluation.

Reproducible benchmarking

Compare models under the same deterministic split sequence.

Interview questions

QWhat does RepeatedKFold do?

It is a cross-validator that repeats K-fold cross-validation n_repeats times. Each repetition uses a different randomization, and split yields training and test indices.

Follow-up: How do you make the generated partitions repeatable? Set random_state to an integer.

QWhat are the main structural parameters?

n_splits controls the number of folds in each repetition, while n_repeats controls how many complete K-fold runs are performed. The default values are 5 and 10, respectively.

Follow-up: What constraint applies to n_splits? It must be at least 2.

QHow does random_state affect behavior?

random_state controls the randomness used for each repeated cross-validation instance. Passing an integer produces reproducible output across multiple calls.

Follow-up: What happens when random_state is left as None? Results may differ between calls to split.

  • KFold
  • RepeatedStratifiedKFold

Source: RepeatedKFold — scikit-learn 1.9.1 documentation. Checked 2026-10-15.