betting_combat.ml.cv
Purged combinatorial cross-validation (Lopez de Prado, AFML ch. 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.
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).
Classes
PurgedCPCV
groups
groups(d: pd.DataFrame) -> pd.SeriesGroup number per row: cards split into n contiguous time blocks of similar size.
splits
splits(d: pd.DataFrame) -> Iterator[Split]Yield (test_groups, train_index, test_index, purged_fights) with the purge applied.
Functions
card_dates
card_dates(d: pd.DataFrame) -> pd.Seriesevent_id -> event_date, one per card, in (event_date, event_id) order.