A ball-by-ball T20 cricket engine built on Markov chains over 17 seasons of IPL ball-by-ball data. Every transition is a real historical transition. Venue, phase, and bowler-type multipliers re-weight the probabilities. The Opponent Strategy AI sits on top as a prototype classifier layer — and I'm honest about which parts of it work and which don't.
Most cricket prediction work asks the wrong question: what will the final score be? A coach asks a different question — what does the rest of the match look like from here? If we're 80/4 in over 12 chasing 170, what's the realistic distribution of where the innings ends? If the same situation moves from Wankhede to Chepauk, how does that distribution shift?
A point-estimate score predictor can't answer that. A bootstrap from historical matches can't either, unless an exact past match matches the current state. What's needed is something that can simulate the rest of an innings from any state, ball by ball, with a stochastic engine that's grounded in real cricket — not a regression artifact.
That's what this is.
The simulator represents an innings as a sequence of states. Each state is three integers: cumulative runs, cumulative wickets, ball number. From the IPL ball-by-ball dataset, every observed transition between consecutive states across 17 seasons is counted, and the counts become transition probabilities. To simulate a match, you start at (0, 0, 0), sample a next state proportional to its historical frequency, jump to it, repeat. Every transition is real.
Deliveries and matches tables joined on match_id. Compute ball_number, mark is_wicket from dismissal_kind, compute cumulative runs and wickets per match.
Each delivery becomes a tuple (cumulative_runs, cumulative_wickets, ball_number). Using shift(-1) within each match, pair every state with its next state. The result is a long list of (current_state → next_state) pairs across hundreds of thousands of deliveries.
For every observed current_state, collect all the next_states that followed it. Count each unique next-state; divide by the total to get a probability. The result is a dictionary mapping each state to a list of (next_state, probability) pairs — the trained Markov chain.
Hand-tuned re-weights on top of the base probabilities. Wankhede (1.1), Chepauk (0.9), Chinnaswamy (1.2) reflect pitch character. Phase factors push Powerplay (1.1) and Death (1.3) over the Middle. Spin (0.8) restricts vs Pace (1.0). Probabilities normalized to sum to 1 after re-weighting. Honest note: these are domain-informed guesses, not learned parameters. V2 replaces them with venue-conditional transition tables.
Start at (0, 0, 0). At each step: look up the current state's transitions, apply the multipliers, sample the next state via random.choices() weighted by adjusted probabilities. Walk until 120 balls used or 10 wickets lost. Output is a DataFrame of every state visited — a complete simulated innings trajectory.
ipywidgets dropdowns for venue and bowler type, with a Simulate button that runs the chain and plots runs and wickets progression with Plotly. Visualizes the trajectory ball-by-ball.
Three RandomForest classifiers — one per phase — attempting to predict opposition tactics from match metadata (team, venue, toss). This layer is exploratory; the next section explains exactly what works in it and what doesn't.
The Strategy AI layer has three RandomForest sub-models. None of them are publication-grade. They're in the notebook as scaffolding for V2 — and rather than hiding the inflated metrics or quietly cutting the section, the right move is to lay them out and explain exactly why each accuracy number is a red flag instead of a result.
spin_overs, team_bowling_strength, and opposition_weakness are all generated by np.random.randint. Noise predicting noise. The 0.53 is exactly what you'd expect from chance.The reason these are in the writeup is the same reason the 1.0 accuracy is left in the notebook: knowing what overfitting looks like in a small categorical feature space is more useful than pretending the number is real. V2 rebuilds the strategy classifiers with stratified train/test, leave-one-team-out cross-validation, and features that aren't randomly generated.
The simulator is the strong half. These are the specific things I'd attack first in V2.
Notebook on GitHub. Open the Markov chain, inspect any state's transitions, run the simulation yourself.