Skip to content

API reference / Evaluation

tsdive.eval.GroupSplit dataclass

GroupSplit(
    group_col: str,
    stratum_col: str,
    n_folds: int,
    seed: int,
    fold_of_group: dict[str, int],
    folds: tuple[tuple[str, ...], ...],
    fold_sizes: tuple[int, ...],
    strata_counts: tuple[dict[str, int], ...],
    group_sizes: dict[str, int],
)

A k-fold split in which every group sits entirely inside one fold.

Methods:

Name Description
groups

The group keys held out in fold.

test_indices

Row positions of items whose group is held out in fold.

train_indices

Row positions of items whose group is not held out in fold.

strata_present

The strata with at least one item in fold.

leakage_check

Refuse a split where any group reached more than one fold.

Attributes:

Name Type Description
group_col str
stratum_col str
n_folds int
seed int
fold_of_group dict[str, int]
folds tuple[tuple[str, ...], ...]
fold_sizes tuple[int, ...]
strata_counts tuple[dict[str, int], ...]
group_sizes dict[str, int]

group_col instance-attribute

group_col: str

stratum_col instance-attribute

stratum_col: str

n_folds instance-attribute

n_folds: int

seed instance-attribute

seed: int

fold_of_group instance-attribute

fold_of_group: dict[str, int]

folds instance-attribute

folds: tuple[tuple[str, ...], ...]

fold_sizes instance-attribute

fold_sizes: tuple[int, ...]

strata_counts instance-attribute

strata_counts: tuple[dict[str, int], ...]

group_sizes instance-attribute

group_sizes: dict[str, int]

groups

groups(fold: int) -> tuple[str, ...]

The group keys held out in fold.

test_indices

test_indices(items: DataFrame, fold: int) -> list[int]

Row positions of items whose group is held out in fold.

train_indices

train_indices(items: DataFrame, fold: int) -> list[int]

Row positions of items whose group is not held out in fold.

strata_present

strata_present(fold: int) -> set[str]

The strata with at least one item in fold.

leakage_check

leakage_check() -> None

Refuse a split where any group reached more than one fold.

Also refuses a fold list that disagrees with fold_of_group or that omits a known group: a split whose bookkeeping is wrong is not a split whose numbers may be published.