cleverly.learners.make_folds#

cleverly.learners.make_folds(n: int, n_folds: int = 10, *, stratify: ndarray[tuple[Any, ...], dtype[float64]] | None = None, cluster: ndarray[tuple[Any, ...], dtype[int64]] | None = None, random_state: int | Generator | None = None) → Folds[source]#

Build a cross-fitting partition of n observations.

Parameters:
nint

Number of observations to partition.

n_foldsint

Folds requested. Reduced, with a warning, when the data cannot support it.

stratifyndarray or None

Labels to balance across folds. Pass the treatment indicator.

clusterndarray or None

Cluster codes; every row of a cluster lands in the same fold.

random_stateint, Generator, or None

Seed or generator. The split is deterministic given an integer seed, so a fit is reproducible. None draws a fresh seed for an unstratified split, which the returned Folds.origin records.

Returns:
Folds

A checked partition, cluster-respecting and stratified as asked.

Notes

Without stratify the split comes from random_partition(), which does not depend on the installed scikit-learn. With stratify it comes from StratifiedKFold or, with cluster, from StratifiedGroupKFold.