PROJECT / BBLMLP
BBLMLP
A baseball machine learning pipeline I built. It predicts each MLB game's home-win probability from features that only know what was known before first pitch, then scores those probabilities the way a skeptic would: walk-forward, paired against a tuned baseline, and checked for calibration.
Research project · model not shipped · off-season since mid-September 2026
- RESULT
- A tie, on recordStacked LightGBM vs a tuned two-constant Elo: Brier 0.24554 each
- HELD-OUT GAMES
- 6,7512024 to 2026, paired t = −0.00
- AT-BATS MODELED
- 1,066,558Plate-appearance layer, 2021 to 2026
- ISOTONIC CALIBRATION
- Rejected by its own gatePre-registered gate: 0 of 3 fittable folds improve, so it did not ship
- TESTS COLLECTED
- 1,282Hermetic: no warehouse, no network
- CODE
- 17.2k linesPython across 74 modules, plus 19.2k lines of tests
What it is
BBLMLP is a machine learning and data engineering project I built, using baseball as the domain for practicing the parts of ML that are easy to get wrong: feature pipelines, leakage-safe validation and probability calibration. It ingests MLB data from 2021 to 2026 into a DuckDB warehouse, builds point-in-time features, trains a tuned Elo baseline and a stacked LightGBM, and evaluates both walk-forward.
Figure 1 · The pipeline
One local DuckDB file, driven by one command-line tool.
- 01 / INGESTMLB dataStatsAPI, Statcast, season tables, weather. 2021 to 2026.
- 02 / FEATURESPoint-in-timeRolling windows, each rate with a shrunk sibling. No lookahead.
- 03 / MODELSElo + LightGBMElo, stacked into a gradient-boosted model.
- 04 / EVALUATEWalk-forward16-cell matrix, paired tests, pre-registered gates.
- 05 / SERVEDaily projectionsSame feature code as training, as-of the game date.
SIMULATION BRANCH, SAME WAREHOUSE
- BUILTPlate-appearance layer1,066,558 at-bats, base-out transitions, park factors.
- DESIGNED, NOT BUILTGame simulatorMonte Carlo and Markov chain.
Source: bblmlp README and docs/public-facts.yaml (2026-10-15).
The data
- Sources: MLB StatsAPI for schedules, results, lineups and umpire crews; Statcast pitch-level data through pybaseball; season tables, standings and the Chadwick player-id crosswalk; Open-Meteo weather, with the wind resolved against each park.
- One DuckDB warehouse. Rolling features are window functions over game-level rollups, and every rate has an empirical-Bayes shrunk sibling.
- A row-count gate: 13,952 training rows, one per decided game from 2021 to 2026, checked against a direct count of games.
Leakage controls
Every feature is an as-of value, and the tests enforce it rather than a convention.
- Each rolling window ends one row before the game it describes, and tests perturb a game's own statistics to prove its features do not move.
- Splits are strictly time-ordered. The splitters have no shuffle option, and a test keeps it that way.
- Probable pitchers and Elo ratings use only rows from before the game.
- Train/serve parity. One function builds features for training and for daily projections. 524 of 528 sampled games reproduce every non-lineup feature on the serving path, and the four exceptions are named.
Models
- A tuned Elo baseline. Elo's usual k = 20 is borrowed from chess. Tuned on 2021 to 2023 (k = 8) and scored once on 2024 to 2026, it beats k = 20 by 0.00362 Brier.
- A stacked LightGBM. The Elo probability goes in beside rolling team, starter, bullpen, batter and lineup features. It uses 7 leaves, chosen by monotonicity because Brier could not separate 7, 15 and 31; at 31 the model had learned that a bullpen walking more batters helps its own team.
- A plate-appearance layer for simulation. 1,066,558 at-bats feeding base-out transitions and park factors. One finding: Coors Field is the league's top hit park, not its top home-run park.
Evaluation
- Walk-forward by season. Each test fold is one whole season, trained on every season before it. Test seasons run 2022 to 2026.
- Every variant reported. 16 model variants sit beside four naive baselines. Brier picks the model; log loss, calibration error and reliability diagrams are reported with it, and comparisons are paired on identical games.
- A pre-registered calibration gate. Isotonic calibration ships only if it improves Brier and calibration overall and in most season folds. It improved none of the 3 folds it could be fit on, so it does not ship.
The honest result
The stacked LightGBM ties a tuned two-constant Elo on Brier. That tie is the finding, recorded as the result of the model cycle in October 2026, instead of re-running the search until a model looks good. The model's earlier margin over Elo (+0.00376) was a margin over an untuned baseline: nothing about the model got worse, the yardstick got honest.
Table 1 · Head to head
The 6,751 games from 2024 to 2026 that the Elo tuning never saw, paired on identical games. Lower Brier is better.
| MODEL | BRIER |
|---|---|
| Stacked LightGBM | 0.24554 |
| Tuned Elo (k = 8, season regression 0.5) | 0.24554 |
| Paired difference | −0.00000 |
| Standard error, paired t | 0.00085, t = −0.00 |
Source: docs/handoff-model.md, section 0; config/settings.yaml. Measured 2026-08-12.
Across all 16 variants, the best one beats the tuned Elo by 0.00008 Brier, inside the tie band, and its own calibration gate says not to ship it.
A leak caught in its own evaluation
The model is also scored against an external probability benchmark, and the first comparison made the benchmark look far ahead. It was a leak, not skill: 5.5% of the captured rows were taken after first pitch, because game times stored in UTC were joined against local capture times. With pregame rows only, the benchmark's Brier on the same 180 games went from 0.14861 to 0.24448, against the model's 0.24656. The evaluation now refuses any post-first-pitch row, and the honest comparison is a statistical tie (324 games, paired t = −0.37).
Engineering
- About 17.2k lines of Python across 74 modules, plus about 19.2k lines of tests: 1,282 tests, all hermetic (no warehouse, no network), run by GitHub Actions on every pull request.
- Real-data gates before merge. Checks that need the full warehouse (train/serve parity, run reconciliation, row counts) run locally, and their numbers go into the design spec.
- A scheduled daily chain keeps data, features and projections current in season, with a timeout on every step and a retry the next day.
What is next
- A game simulator: Monte Carlo and Markov chain, on top of the plate-appearance layer. Designed, not built.
- A total-runs model, the most promising use of umpire features.
- Better priors for the batter grain and the plate-appearance rates.
The repository is private. Code available on request: [email protected].
Sources: every number on this page comes from the project's own records (docs/public-facts.yaml, docs/handoff-model.md, docs/OPEN-ITEMS.md, the model design spec, config/settings.yaml and the CI workflow), measured 2026-07-28 to 2026-10-15.