Skip to content

betting_combat.ml.cv

Purged combinatorial cross-validation (Lopez de Prado, AFML ch. 7 and 12) over cards.

Groups: every row’s card (event_id) is assigned to one of N contiguous time groups by its date (event_date; cards on one date in event_id order, so no tie is left to a sort); a card never straddles two groups. Each split holds out k groups as the test set and trains on the rest: C(N, k) splits, and every row is tested in C(N - 1, k - 1) of them.

Purge (why and what): a fighter-history feature of a fight is built from that fighter’s earlier results, so a training fight dated AFTER a test fight of the same fighter carries the test fight’s result inside its features. Every such training row is removed: for each fighter in the test set (fighter_a_id / fighter_b_id), all of that fighter’s training fights after his first test fight. Rows before the test fights are safe. (A fight’s label is decided inside its own card, and a card never straddles two groups, so no label spans a block boundary: the label purge of AFML 7.4.1 removes nothing more.)

Embargo (AFML 7.4.2, embargo_days): features that pool many fights (league rates, the style-matchup records) also look back, so a training card just after a held-out group carries some of the group’s results in them. The embargo drops every training fight dated within embargo_days after each held-out group’s last card. 0 = none (the refit’s layer 1: the walk-forward check of 2026-10-22, every model refitted on the past only before each of 34 cards, matched it to the dollar); the strategy paths use one. It cannot reach a look-back of a year: the Bayesian clock of a year is fitted on every year before it, so a held-out group’s results stay in the next year’s clock features (a pooled curve; small, accepted, as in the refit’s own CPCV).

Paths (AFML 12.4): the held-out predictions recombine into phi = C(N - 1, k - 1) complete histories, each covering every group exactly once (paths, assemble): a strategy is judged on that spread of histories, not on one.

over (groups, splits, assemble): the rows whose cards are cut into the groups (default: all of them). The other cards of the frame (e.g. the years before the trading era) are never held out and train, purged and embargoed like the rest; one dated inside a held-out group’s span (a card of the era without trading rows) is dropped with it.

The frame needs event_id, event_date, fight_id, fighter_a_id and fighter_b_id; any number of rows per fight (round starts, candidate bets).

Research: ufc/modeling/cpcv.py (PurgedCPCV); the reference splitter is genesis-v2’s models.cv (CombinatorialPurged, Purge, Embargo).

Classes

PurgedCPCV

assemble

assemble(d: pd.DataFrame, predictions: Sequence[pd.DataFrame], over: pd.DataFrame | None = None) -> list[pd.DataFrame]

The paths’ complete histories: predictions[s] is split s’s predictions, indexed like d, on (at least) its held-out rows; path j’s rows of group g come from split paths()[j, g]. Rows of cards outside the groups belong to no path.

combinations

combinations() -> list[tuple[int, ...]]

The held-out groups of each split, in splits order.

groups

groups(d: pd.DataFrame, over: pd.DataFrame | None = None) -> pd.Series

Group number per row: cards split into n contiguous time blocks of similar size (the cards of over, default d; a card of d outside them: -1, never held out).

paths

paths() -> np.ndarray

(n_paths, n_groups): the split (in splits order) path j takes for group g, the j-th split that holds g out (AFML 12.4).

splits

splits(d: pd.DataFrame, over: pd.DataFrame | None = None) -> Iterator[Split]

Yield (test_groups, train_index, test_index, removed_fights) with the purge and the embargo applied (removed_fights: the training fights either took out).

Functions

card_dates

card_dates(d: pd.DataFrame) -> pd.Series

event_id -> event_date, one per card, in (event_date, event_id) order.