sport-intelligence-benchmark / DATA_PROVENANCE.md
FedCal's picture
Mirror sport-intelligence-benchmark on HF (Zenodo concept DOI 10.5281/zenodo.21602378)
6acb11f verified
|
Raw
History Blame Contribute Delete
7.87 kB
# Data Provenance and Methodology
This document explains exactly what data ships with this repository, how
it was generated, and how the reproduction numbers relate to the
production headline result (Brier 0.5783 over 97,000 real matches).
## What is shipped
`data/derived_sample.csv` is a **fully synthetic** dataset: every row is
procedurally generated by `export_dataset.py` from latent random team
strengths, NOT sampled, aggregated, or derived from any third-party row.
It is **not**:
- A copy, subset, or statistical aggregate of football-data.co.uk CSV
rows.
- A copy, subset, or statistical aggregate of any other third-party
live-odds/match-data provider integrated elsewhere in the monorepo
pipeline.
- An export of the production PostgreSQL `sport_intelligence.fixture`
table.
The only thing carried over from the production pipeline is the
**feature schema** (25 column names and their semantics, taken from
`app/sport_intelligence/features/db_extractor.py` `FEATURE_NAMES_V2`) -
this is this project's own original feature-engineering design, not
third-party data, so publishing the schema and synthetic values under it
carries no third-party licensing risk.
## Why synthetic, not a real-data aggregate
The project's own ingestion code flags the football-data.co.uk licensing
question as unresolved:
```
# ml-service/app/ingestion/datasets/football_results_2018_2026.py, line 37
LICENSE = "Verificare commercial use con football-data.co.uk"
```
A separate live-odds source integrated elsewhere in the monorepo
pipeline carries an explicit `is_public_redistribution_allowed=False`
marker in its own ingestion source configuration and must never be
redistributed in any form (raw or aggregated).
Rather than resolve an unverifiable third-party licensing question by
guessing, this repository sidesteps it entirely: the shipped sample
contains zero third-party data, in any form, at any aggregation level.
Anyone who wants to train on the real historical data can point
`export_dataset.py`'s feature schema at their own football-data.co.uk
export (see "Bring your own data" below).
## The Brier score: exact definition and scale
Both this repository's `run_benchmark.py` and the production
`app/sport_intelligence/training.py` (`compute_metrics`) /
`app/sport_intelligence/models/metrics.py` (`brier_score_1x2`) use the
**same, exact formula** - the classic multi-class (3-outcome) Brier
score, summed across classes per sample, then averaged across samples:
```
brier = mean_over_samples( sum_over_k in {home, draw, away} of (p_k - y_k)^2 )
```
where `p_k` is the calibrated predicted probability for outcome `k` and
`y_k` is the one-hot ground truth (1 for the actual outcome, 0
otherwise).
**Range:** `[0.0, 2.0]` per sample (0.0 = perfect probabilistic
prediction, 2.0 = maximally wrong with full confidence). This is the
standard, textbook multi-class Brier formulation for a 3-outcome
problem (Brier, 1950) - not a project-specific variant.
**Reference points on this scale:**
- Uniform-prior baseline (predicting 33/33/33 for every match):
`2 x (1/3)^2 + (2/3)^2 = 2/9 + 4/9 = 6/9 ≈ 0.667`.
- Production headline result: **0.5783** (a real, if modest, edge over
the uniform baseline - consistent with the widely documented
difficulty of football 1X2 prediction).
## Reconciling 0.5783 vs. the project's separately-stated "<0.21" target
Project planning documents elsewhere state a target of "Brier < 0.21"
for the Sport Intelligence model. This is **not a contradiction** - it
is a different, but closely related, scale convention:
```
0.5783 / 3 ≈ 0.1928 (< 0.21)
```
Dividing the 3-class-summed Brier by the number of classes (3) yields
the **per-outcome average squared error**, which is the convention used
by some sports-analytics literature and dashboards that report Brier
"per probability" rather than "summed across all three simultaneous
probabilities for one match." Both are legitimate ways to report the
same underlying calibration quality; this repository is explicit about
using the summed (0.0-2.0 range) convention throughout, matching the
project's own `metrics.py` source of truth, and shows the reconciling
division here so the two numbers that appear in different project
documents do not read as inconsistent.
## What `run_benchmark.py` actually reproduces
`run_benchmark.py` reproduces the production **methodology**, not a
bit-exact copy of the production **number**:
1. It fits the same class of meta-learner (`LGBMClassifier`, identical
hyperparameters to `app/sport_intelligence/training.py`
`fit_meta_learner`), with a `LogisticRegression` fallback if LightGBM
is not installed - exactly mirroring the production fallback chain.
2. It fits 3 per-class `IsotonicRegression` calibrators, exactly as
production does.
3. By default (in-sample mode, matching
`app/sport_intelligence/training.py train_full_pipeline`, which fits
and evaluates `compute_metrics` on the **same** `(X, y)` used for
training - i.e. the production headline number is an in-sample
metric, not a held-out validation score), it evaluates on the same
rows used for fitting.
4. A `--holdout` flag is also provided, which instead does a 75/25
stratified split and evaluates strictly out-of-sample, for readers
who want the more conservative, generalization-aware variant.
Because the shipped sample is synthetic and much smaller (a few thousand
rows) than the real 97,000-match production dataset, the **magnitude**
of the printed Brier score will differ from 0.5783 - a small synthetic
sample lets a 200-tree LightGBM model fit the in-sample rows far more
tightly than a real 97k-row noisy dataset would allow, producing a much
lower (better-looking) in-sample number on the synthetic sample. This is
expected and is not evidence of a bug: the point of `run_benchmark.py`
is to prove the pipeline mechanics are correct and standalone-runnable,
not to force-match a number computed on data this repository
intentionally does not ship.
## Trade-off: in-sample vs. held-out evaluation
Reporting an in-sample Brier score (as the production pipeline does) is
a genuine methodological trade-off, not an oversight:
- **Pro:** it reflects the exact number the production system reports
and monitors over time (drift_monitor.py compares against this same
convention), and for a well-regularized model with isotonic
calibration fit on the same fold, the gap to true out-of-sample
performance is typically modest for large-N datasets (97k rows).
- **Con:** in-sample metrics are optimistic estimates of generalization
by construction; a held-out or walk-forward backtest (see
`app/sport_intelligence/backtesting.py` in the main monorepo) is the
more rigorous number for claims about future predictive performance.
This repository ships both variants (`run_benchmark.py` default vs.
`run_benchmark.py --holdout`) specifically so a reader can see the
difference in magnitude directly, rather than being presented with only
the more favorable number.
## Bring your own data
To benchmark on real historical results instead of the synthetic sample:
1. Download historical CSVs directly from
<https://www.football-data.co.uk/data.php> for the leagues/seasons
you are interested in, subject to that site's own terms.
2. Compute the 25 `FEATURE_NAMES_V2` columns from your own data (Dixon-
Coles probabilities, Elo probabilities, market-implied probabilities,
rolling form, days rest, head-to-head, lineup rating) - the feature
engineering logic is documented in this repository's README and, in
full, in the main portfolio monorepo's
`app/sport_intelligence/features/` and `app/sport_intelligence/training.py`.
3. Save the result as a CSV with the same column names as
`data/derived_sample.csv` and pass it to `run_benchmark.py --data
your_file.csv`.