A 3-stage end-to-end ML system predicting an ODI cricket match from before the toss to the final ball. Calibrated probabilities, temporal train/val/test splits, ICC-style ratings, deployed as a public Streamlit app. Trained on 2,520 ODIs and 1.3 million deliveries from Cricsheet.
Open any cricket telecast. There's a win-probability bar at the bottom of the screen. It moves. Sometimes it makes sense; sometimes it jumps 15% on a single dot ball. Nobody knows where the number comes from, whether it's calibrated, what features it uses, or how the model was trained. Most existing cricket-prediction tools fall into one of two camps: pre-match odds models that ignore the live state, or live-state models that ignore team strength and form. No tool covers the full match continuously, transparently, with calibrated probabilities.
And no public tool lets you ask the question scouts and broadcasters actually want to ask: "swap this player into the XI — what happens to the win probability?"
That's the gap this project closes.
The pipeline outputs a continuous, calibrated win probability from before the toss to the final ball. Each stage uses a different model — chosen for the data it has, not by default.
13 features per match — team Elo ratings, batting/bowling rating differentials, recent form, head-to-head record, toss winner, batting order, venue intelligence. Trained on 2,005 matches up to 2022. Beat XGBoost and Random Forest at validation.
Snapshot the match at every over-end. 13 features: cumulative state, current run rate, phase encoding, venue context, team Elo. Point predictor plus q=0.10 and q=0.90 quantile regressors for honest 10/90% confidence bands.
14 features per over-snapshot — including the killer rrr_crr_diff (35.7% importance) and the pre-match probability as a prior. Sharp nonlinearities + sufficient samples make XGBoost the right call here.
Cricsheet ships each match as a YAML — match info plus a list of innings with delivery-level records. The tricky bit: delivery keys are floats like 0.1 and 14.7 meaning "over 0 ball 1" and "over 14 ball 7". Splitting on the decimal parses them. The parser handles 2,520 files into clean DataFrames.
Standard Elo with two ICC-specific tweaks. Variable K-factor: K=50 for World Cup / Champions Trophy matches, K=32 for bilateral series — a loss in a tournament says more than a loss in a friendly. Recency weighting: last 12 months count at weight 1.0, 12–24 months at 0.5, older ignored. Sanity check: top 6 weighted ratings come out as India, Australia, England, NZ, SA, Pakistan. ✓
Per innings: batting rating = runs × (SR/100) × opposition × venue × innings_factor — rewards volume, speed, tougher bowling, harder pitches, chasing pressure. Bowling rating = wickets × 25 + dots × 0.5 − economy × 3. Each player gets a 10-match rolling weighted average (recent = 1.0, 10 ago = 0.1) plus a 5% decay if inactive 60+ days.
Average 1st-innings score, PP/Middle/Death scoring averages, chasing win rate, toss-bat win rate, spin vs pace wicket ratio, frequency of 300+ scores. Wankhede and Chennai have completely different signatures — venue features capture that. Spin classification uses an economy < 5.5 heuristic when bowl_style metadata is missing.
Train on matches up to 2022-12-31 (2,005 matches). Validate on 2023 (186 matches) — used for model selection and calibration fitting. Test on 2024+ (201 matches) — never touched until the end. A random split would let the model train on 2024 and test on 2020. That's deployment-impossible and unfaithfully optimistic.
All three models compared on the validation set: LR 68.8%, RF 65.1%, XGBoost 59.1%. LR wins because with 13 features × 2,005 rows, tree boosting has too many degrees of freedom and overfits. The team-strength-to-win-probability relationship is roughly monotonic — LR's linear decision boundary is the right inductive bias. Match the model to the data, not the trend.
Snapshot the match state at every over-end (50 per match × 2,392 valid matches = ~120k rows). Train a GradientBoostingRegressor for the point prediction, plus two XGBRegressors with objective='reg:quantileerror' at q=0.10 and q=0.90 for the confidence band. Bundle all three into one .pkl. Top feature: current run rate, ~55% importance.
Same training size as Stage 1, but live state has sharp nonlinear interactions — rrr_crr_diff crossing zero is a regime change, wicket cliffs after a fall, partnership momentum compounding. Tree boosting handles these well. The pre-match probability is itself a feature here — Stage 3 inherits Stage 1's prior instead of relearning it.
Wrap both Stage 1 and Stage 3 in CalibratedClassifierCV with isotonic regression, fitted on the 2023 validation set. A 70% prediction has to mean a true 70%, or the app lies. Brier scores: pre-match 0.248 (honest, barely beats random 0.25 — the modesty is real), 2nd innings 0.146 (well-calibrated).
Three .pkl bundles + small ratings CSVs load at cold-start (~10s). Phase 1: pre-match setup — probability. Phase 2: 1st innings, score per over — projected total + win prob. Phase 3: 2nd innings, score per over — chase prob. 12 MB repo (training data lives elsewhere). Push to GitHub → Streamlit auto-redeploys → public URL stays live.
The honest gaps between this and a production-grade broadcast-quality system. Each one is a real V2 target, not hand-waving.
batting_quality — the team's average rating — not the specific batter at the crease. A 200-rated tailender at 80/3 and an 800-rated opener at 80/3 look identical to Stage 3.Public Streamlit app — set up a match, enter scores per over, watch all three stages predict in real time.