A Fantasy Cricket system: rule-based venue tagging from historical scoring patterns, a faithful Dream11-schema fantasy points calculator, and an Integer Linear Program that selects the optimal 11-player team under credit constraints. The notebook also includes two ML experiments — both kept in the writeup as a teaching moment on target leakage.
This is the hardest project on my portfolio to write up honestly. The notebook contains two ML models with target leakage — they predict labels that are deterministic functions of their own input features. Their reported metrics (Accuracy 1.0, R² 0.998) are the textbook tells.
Rather than hide them or fix them silently, I'm leaving them in and explaining exactly what went wrong, because the habit they cost me to learn — if your metric is too good, audit the feature-target dependence — is more valuable than any single result.
The genuine engineering in this project is the rule-based venue tagger, the Dream11-schema fantasy points calculator, and the PuLP LP for Fantasy XI selection. Lead with those. The ML experiments are a story about a mistake.
Three if/then rules on first/second-innings run rate and wicket rate classify IPL grounds as Batting-friendly, Bowling-friendly, or Neutral. Not ML — a deterministic heuristic. Useful as a feature for downstream tasks.
Faithful implementation of the actual Dream11 fantasy scoring rules: runs, fours, sixes, milestone bonuses, duck penalty, wickets, wicket-haul bonuses. Real engineering, real schema.
PuLP Integer Linear Program: 11 players, credit cap of 100, role minimums. Decision variables are binary. CBC solves in under a second. Has a string-matching bug in the role constraints — flagged honestly below.
The Dream11 fantasy scoring system has dozens of components. This calculator implements the core ones: runs scoring, boundary bonuses, milestone bonuses (30+, 50+, 100+), wicket points, and wicket-haul bonuses (3 wickets, 4+ wickets). The duck penalty fires on a zero score with balls faced. Per-player-per-match.
Deliveries, matches, and player style metadata joined on match_id and bowler. Result: every delivery tagged with venue, season, toss, winner, and the bowler's style (pace/spin/all-rounder).
Per ground: average runs per over, wicket rate, first/second-innings run rate split, pace vs spin wicket counts, phase-wise run distribution (PP/Middle/Death). These are genuinely useful features — clean, interpretable, reusable.
Three conditions: Batting-friendly if both innings RR > 9 and wicket rate < league average. Bowling-friendly if both innings RR < 8 and wicket rate > league average. Neutral otherwise. Deterministic — same input always gives same label. Not ML.
Group ball-by-ball by (match_id, player) to get batting and bowling lines per player. Apply the Dream11 schema above. Faithful implementation of the actual fantasy scoring rules.
One binary decision variable per player. Linear objective: maximize total fantasy points. Linear constraints: exactly 11 players, total credits ≤ 100, role minimums for bowlers / all-rounders / WK / batsmen. Caveat: the role constraints have a string-matching bug — flagged in the limitations.
Branch-and-bound on the LP relaxation. For a problem this size, sub-second convergence. Returns an exact-optimal Fantasy XI under the active constraints.
The notebook contains two ML models. Both report metrics that look elite. Both are reverse-engineering their own labeling functions. Here's exactly what went wrong, why the metrics are misleading, and what the honest version of each task would look like.
The label venue_type is computed from a three-condition rule on first_innings_rr, second_innings_rr, and wicket_rate. Those exact three columns are then passed as features to a RandomForest and an XGBoost classifier.
The honest version: predict pitch type from features that don't define it — weather conditions, soil type, days since the last match, time of year, time of day. That's a real prediction problem with no leakage.
The target is literally 25 × wickets + 1 × runs + 1 × fours + 2 × sixes + bonus(runs). The regressor's features include wickets, runs_scored, fours, sixes. The model learns the linear combination of its own inputs.
The MAE of 0.328 on integer-stepped fantasy points is the giveaway. You don't get a sub-1 MAE on integer targets unless you're recovering the formula directly.
The honest version: predict expected next-match fantasy points from pre-match features only — recent form, opponent quality, venue type, pitch report. That's a forecasting task with real uncertainty.
Beyond the leakage issue, the gaps between this and a production-grade fantasy cricket tool.
'Bowler ' not 'Bowler') and inconsistent naming ('Batsman' vs the code's 'Batter'). The check 'Bowler' in role_counts evaluates False, so the constraints never get added to the LP. Output shows a player with role None — the tell.np.random.uniform over buckets derived from average fantasy points — circular dependence between cost and value. Real Dream11 credits are exogenous; these aren't..str.strip() + normalize 'Batter' / 'Batsman' / 'WK-Batsman'.Full notebook on GitHub — the working pieces, the broken ML models, and exactly what target leakage looks like.