cleverly.learners.Folds#

class cleverly.learners.Folds(assignment: ndarray[tuple[Any, ...], dtype[int64]], n_folds: int, origin: FoldOrigin | None = None)[source]#

A cross-fitting partition.

assignment[i] is the index of the fold that holds out observation i. Iterating yields (train_index, test_index) pairs like scikit-learn.

Parameters:
assignmentndarray

assignment[i] is the index of the fold that holds out observation i.

n_foldsint

Number of folds the assignment ranges over.

originFoldOrigin or None, default=None

How random_partition() drew the split. None for a split from any other source: a stratified split or a hand-built one. Equality ignores it, because two splits with the same labels hold out the same rows.

Methods#

classmethod Folds.single(n: int) → Folds[source]#

A degenerate partition that trains and predicts on all rows.

This is the cross_fit=False path – it reproduces R’s cvQinit = FALSE behaviour, where the initial fit is evaluated on the same data that produced it.

Parameters:
nint

Number of observations.

Returns:
Folds

A one-fold partition holding every row.

Folds.test_index(fold: int) → ndarray[tuple[Any, ...], dtype[int64]][source]#

Return held-out row indices for one fold.

Parameters:
foldint

Fold index.

Returns:
ndarray

Positions of the rows that fold holds out.

Attributes#

Folds.is_single#

Return whether this object contains one fold.

Folds.n#

Return the number of observations.

Folds.origin: FoldOrigin | None = None#
Folds.assignment: ndarray[tuple[Any, ...], dtype[int64]]#
Folds.n_folds: int#