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
nobservations.- Parameters:
- n
int Number of observations to partition.
- n_folds
int Folds requested. Reduced, with a warning, when the data cannot support it.
- stratify
ndarrayorNone Labels to balance across folds. Pass the treatment indicator.
- cluster
ndarrayorNone Cluster codes; every row of a cluster lands in the same fold.
- random_state
int,Generator,orNone Seed or generator. The split is deterministic given an integer seed, so a fit is reproducible.
Nonedraws a fresh seed for an unstratified split, which the returnedFolds.originrecords.
- n
- Returns:
FoldsA checked partition, cluster-respecting and stratified as asked.
Notes
Without
stratifythe split comes fromrandom_partition(), which does not depend on the installed scikit-learn. Withstratifyit comes fromStratifiedKFoldor, withcluster, fromStratifiedGroupKFold.