Chapter 39 Exercises — Capstone: Your Cricket Analytics Platform

Difficulty: ⭐ recall and explain · ⭐⭐ calculate and interpret · ⭐⭐⭐ build or judge · ⭐⭐⭐⭐ open project

All numbers come from the chapter's real runs (scripts in code/, outputs in code/*_output.txt). Code exercises extend the chapter's scripts or project/app.py; run them from the chapter directory unless stated.


Part A — Conceptual ⭐

A1. Crease's dependency graph is a DAG with 28 internal import edges, and its longest chain is batting_order -> live -> winprob -> impact. Explain in your own words why a DAG is easier to test than a package with a circular import, and name one practical consequence of the four-module chain.

A2. Describe the three layers of project/app.py (data and model functions, figure builders, page functions). For each layer, give one thing it must never do.

A3. What is the difference between st.cache_data and st.cache_resource? Which would you use for (a) a fitted WP v1 model, (b) a 70-row table of IPL 2026 matches the page sorts by date, (c) the 260,000-row shrunk matchups table?

A4. The Match Centre fits win probability for a match in season Y only on seasons before Y. State the two separate reasons this matters: one about honesty, one about how the dashboard will be used next season.

A5. What is a smoke test? Give one failure it will catch and one it will not.

A6. What is a reproduction test, as the chapter uses the term? Give the three book numbers the chapter's dashboard reproduced for the IPL 2026 final or the 2026 season.

A7. List the six fields of a model card. Which two fields does the chapter argue are the most useful to a coach, and why?

A8. Kohli made 75 not out off 42 in the IPL 2026 final and was player of the match, yet Rasikh Salam added more win probability. Explain the difference between "contribution to the scorecard" and "contribution to winning" in two or three sentences.

A9. Why does the chapter refuse to call its dashboard figures "screenshots"? What did a headless browser capture actually show, and why?

A10. The pre-match model gave Gujarat 57% and the win-probability model gave Bengaluru 59% at the first ball of the same match. Name the three differences in evidence the chapter identifies.


Part B — Calculation & Interpretation ⭐⭐

B1. WP v1's 2026 re-test on all men's T20 chases scored a Brier of 0.1062 against a base-rate Brier of 0.2500. Compute the Brier skill score, 1 − (model ÷ baseline). Then do the same for the IPL slice (0.0949 v 0.2329). Which is higher, and does that mean the model is better calibrated in the IPL?

Answer

All men's T20: 1 − 0.1062/0.2500 = 0.575. IPL: 1 − 0.0949/0.2329 = 0.593. The IPL skill is slightly higher, but calibration is a different question: the IPL calibration slope was 1.33 (under-confident; chasers won 63.1% of states where the model averaged 56.8%), against 0.99 overall. Skill mixes calibration with resolution (how far forecasts move from the base rate); a model can resolve well and still be miscalibrated.

B2. After 10 overs of the IPL 2026 final Gujarat were 63 for 3. The live projection gave a median of 164 and an 80% range of 135–195; the run-rate projection was 126. Gujarat made 155. Compute each method's miss. Then use the season-wide table (mean miss 16.7 runs for the simulator v 24.0 for run rate × 20 after 10 overs) to say whether this match was typical.

Answer

Simulator: 164 − 155 = 9 runs high. Run rate × 20: 155 − 126 = 29 runs low. The simulator did better than its season average (9 v 16.7); the run-rate projection did worse than its season average (29 v 24.0). Typical direction, slightly flattering to the simulator in size.

B3. De Kock's raw strike rate against off-spin is 112.9 on 1,226 balls; the expected rate for a batter of his skill is 125.8; the shrinkage constant is k = 303 balls. Using shrunk = expected + (n ÷ (n + k)) × (raw − expected), compute the shrunk value and compare it with the dashboard's 115.5.

Answer

n ÷ (n + k) = 1,226 ÷ 1,529 = 0.802. Shrunk = 125.8 + 0.802 × (112.9 − 125.8) = 125.8 − 10.35 = 115.45, which rounds to the dashboard's 115.5. The weakness keeps about 80% of its raw size because 1,226 balls is four times k.

B4. The pre-match model's five settings for the final gave Gujarat 0.562, 0.577, 0.514, 0.571 and 0.509. (a) What is the range? (b) How many probability points is the home term worth with the last team sheets? (c) With the announced sheets? (d) Which single assumption matters most?

Answer

(a) 0.509 to 0.577, a 6.8-point spread. (b) 0.577 − 0.514 = 6.3 points. (c) 0.571 − 0.509 = 6.2 points. (d) Home advantage: switching team sheets moves the answer by about 0.5 points; switching home on or off moves it by about 6.

B5. The tournament simulator gave the real IPL 2026 champion, Bengaluru, a 15.4% title chance on the eve of the season. Compute the log score, ln(0.154), and compare it with a know-nothing forecast of one in ten. By what percentage did the model improve on that baseline in the chapter's scorecard?

Answer

ln(0.154) = −1.871 (the chapter's −1.873 uses the unrounded 0.1537). ln(0.1) = −2.303. Improvement = (2.303 − 1.873) ÷ 2.303 = 18.6%, as in the scorecard.

B6. In the 2026 re-test, Marcel's SR+ projection had RMSE 13.93 against 20.19 for "same as last season" and 15.25 for "everyone is league average". Rank the three methods. Why is "league average" so much better than "last season", and what does that say about one season of SR+?

Answer

Marcel 13.93 < league average 15.25 < last season 20.19. A single season of SR+ carries so much noise that copying it forward is worse than ignoring the player entirely and guessing par. Marcel wins by blending three seasons and regressing towards par by an amount fitted to how reliable the data is (Chapter 25's lesson; Chapter 6's regression to the mean).

B7. The live projection's 80% ranges contained the real IPL 2026 total in 84.5%, 81.7% and 69.0% of innings after 6, 10 and 15 overs (71 innings each). Which checkpoint is a problem? If coverage were truly 80%, how many of 71 innings would you expect outside the range, and how many were outside after 15 overs?

Answer

After 15 overs. Expected outside at 80% coverage: 0.2 × 71 = 14.2 innings. Observed outside after 15 overs: 0.31 × 71 ≈ 22 innings. The late ranges are too narrow, which matches the model card's known weakness; 22 v 14 out of 71 is large enough to take seriously, though one season is still a modest sample.

B8. In Case Study 2, the model said Punjab Kings would miss the top four with probability 4.4% after 35 results. If the model were perfectly calibrated and you watched 100 independent such forecasts, how many misses would you expect? Why can't the 33 "confident calls" in the case study be treated as 33 such forecasts?

Answer

About 4 or 5 (100 × 0.044). The 33 calls are the same few team-seasons re-forecast at eight checkpoints, so they are strongly dependent: Punjab's single miss appears three times, and the near-certain exits of the bottom teams appear many times. Count each team-season once (for example at its most confident checkpoint) before testing calibration.


Part C — Code It ⭐⭐–⭐⭐⭐

C1. Analyze this match ⭐⭐. Change MID in code/02_end_to_end.py to another IPL 2026 playoff (Qualifier 2, 1535464, Rajasthan Royals v Gujarat Titans). Keep the same model window (fit 2023–25). Output: the scorecard lines, the eight-checkpoint WP table, the top six turning points, and the top-three batting and bowling WPA. Then write three sentences on who won the match and when.

C2. Build this metric ⭐⭐. Add a function wpa_share(curve) to a script (not to Crease) that returns, for each team, the share of its total positive WPA earned by bowlers rather than batters. Run it on the IPL 2026 final and on Case Study 1's WPL final. Expected shape: a two-row table per match (team, bat_wpa_pos, bowl_wpa_pos, bowl_share). Interpret the difference between the two finals.

C3. Build this metric ⭐⭐⭐. Extend code/04_model_cards.py to report, for WP v1 on 2026 men's T20 chases, the calibration slope by competition (IPL, T20 Blast, BBL, PSL, men's full-member T20Is), with the number of chases in each. Output: a five-row table (competition, chases, states, mean forecast, observed, slope). Which competition would you flag for drift, and is its sample big enough to act on?

C4. Predict this match ⭐⭐. Use the Match Predictor's data layer directly (app.predictor("t20s_male", "2026-03-08")) to price the 2026 men's T20 World Cup final, India v New Zealand, at a neutral venue and with India at home. (Check the final's date and venue in load_matches("t20s_male") first and freeze the predictor on that date.) Compare with Chapter 24's reported 0.739 and explain any difference.

C5. Optimize this strategy ⭐⭐⭐. Add a page to project/app.py, Bowling Plan, that calls Chapter 31's bowling_plan.plan_milp for one team and shows the optimal over-by-over plan as a table and a coloured strip chart. Requirements: a cached layer-1 function that builds the value matrix; a fig_bowling_plan figure builder; a page_bowling_plan with a team selector; and a new run in code/project_checkpoint.py showing the page passes under AppTest. Do not change any Crease module.

C6. Settle this debate ⭐⭐⭐. "The scoreboard's projected score is good enough after 15 overs." Using the 2026 live re-test machinery in code/04_model_cards.py, compute for every over from 6 to 19 the mean miss of the simulator and of run rate × 20 on IPL 2026 first innings. Output: a 14-row table and a two-line chart. At which over, if any, does run rate × 20 catch up?

C7. Build this metric ⭐⭐. Add three reproduction tests to a new file project/tests/test_reproduce.py: Bengaluru's innings-break WP in the IPL 2026 final (0.865, fit 2023–25), Gujarat's pre-match probability with announced team sheets and home (0.571), and India's 2026 men's T20 World Cup title probability from the eve (0.465, 10,000 simulations, seed 28). Use a tolerance of 0.002. Mark them as slow so the smoke suite stays fast (with pytest, a @pytest.mark.slow decorator; without it, a command-line flag in your own runner).


Part D — Judgment & Format Transfer ⭐⭐⭐

D1. Would the Match Centre's win-probability page work for ODIs? List what you would need from earlier chapters (states, resources, the ODI phase definitions) and what Crease does not yet have. Would a 50-over WP model need the same "era-only" policy as the men's T20 model? Why or why not?

D2. A Test-match version of the Match Centre needs three outcomes (win, draw, loss). Which Crease modules already produce three-way probabilities, and which chapter's model would you use for the fourth innings? What should the page show instead of a single WP line?

D3. A head coach asks you to remove the 80% ranges from the Live Projection page "because the players find them confusing". Write your reply: what you would agree to change, what you would not, and why, using the 2026 coverage numbers.

D4. Eye test v data. Wendell says the WPA chart "insults Kohli". Nusrat says WPA measures contribution to winning. Write a 150-word paragraph for a match report that uses both the scorecard and WPA fairly, without saying either is wrong.

D5. The pre-match model is slightly worse than a coin flip in the IPL out of time. Should the dashboard keep the Match Predictor page for the IPL at all? Argue for one answer, and say what text the page must carry if it stays.


Part M — Mixed / Interleaved ⭐⭐–⭐⭐⭐

M1 (Chapters 6, 11, 39) ⭐⭐. Using app.matchup_table("male"), find the five batters (1,500+ balls) with the largest shrunk weakness against any type (most negative d_sr), and for each report the raw and shrunk strike rates and the interval. How many of the five raw weaknesses would have looked "large" without shrinkage? Relate your answer to Chapter 6's regression to the mean.

M2 (Chapters 13, 34, 39) ⭐⭐⭐. The Auction Board uses Chapter 13's batting-only scale. Add a toggle that shows Chapter 34's all-skills projected value instead (auction.project_values), with the page clearly labelling which scale is shown. Report Pant's and Verma's values on both scales for 2025 and explain why the numbers cannot be compared across scales.

M3 (Chapters 20, 27, 39) ⭐⭐⭐. Build a "second-innings Live Projection": during a chase, show WP v1 and a Monte Carlo of the remaining chase. Use live.simulate_innings with the chase target as a threshold and compare P(reach target) from the simulator with WP v1 at overs 6, 10 and 15 of the IPL 2026 final's chase. Where do they disagree, and why might they?

M4 (Chapters 24, 28, 39) ⭐⭐. Re-run Case Study 2's season path with in-season Elo updating: after each locked-in result, call Predictor.update on a fresh predictor before simulating. Does Punjab's peak top-four probability rise or fall? Does Bengaluru's title probability change?

M5 (Chapters 7, 37, 39) ⭐⭐. Replace the Match Centre's WP figure with a broadcast-format version using storytelling.canvas("broadcast") and type_scale, keeping the labelled swings. Check the labels stay readable at 1280 × 720 pixels.

M6 (Chapters 25, 26, 39) ⭐⭐⭐. The Player Explorer projects from IPL-only history. For a batter with substantial non-IPL balls (for example HC Brook), add a translated projection using translation.project_translated next to the IPL-only one. Report both 2027 projections with ranges, and explain which you would show an auction room.


Part E — Research & Extension ⭐⭐⭐⭐

E1. A women's-first dashboard. Implement roadmap item R3 for the dashboard: every page gains a women's mode that never uses a men's model or table. The Match Predictor needs a women's team-sheet model (Chapter 24's method on WPL, WBBL and women's T20I data); the Matchups page needs the women's shrunk table; the Live Projection page already has a women's chain. Write a model card for each new women's model with an out-of-time test on 2026.

E2. The drift monitor. Implement roadmap item R2 as a script that, for every model on the dashboard, freezes it before the newest season in the snapshot, scores it on that season against its baseline, and compares the result with the model card's stated accuracy. It should print a red flag when the newest season's calibration slope falls outside 0.8–1.25 or coverage of an 80% range falls outside 70–90%. Back-test it: would it have flagged WP v0 in 2023 (Chapter 9's 13.4-point IPL gap)?

E3. Another league's platform. Pick one league outside the IPL (the BBL, the PSL, The Hundred or the WBBL). Make every page of the dashboard default to it and work end to end, then write a one-page README section on what changed and which model cards need league-specific numbers. The Hundred is the hardest: its 100-ball innings need n_balls=100 in the state models (Chapter 19) and its own phases.


Pointers for selected exercises

These are not full solutions (selected full answers are in Appendix I); they tell you what a good answer contains and where it usually goes wrong.

A1. Testability follows from order: with no cycles you can test impact alone, then winprob with a working impact, then live, then batting_order. The practical consequence of the chain is that a change to impact.innings_states can alter the batting-order simulator's output three imports away, so the whole smoke suite must run after any change, not just the changed module's test.

A3. (a) cache_resource: a fitted model is an object you share and do not copy. (b) cache_data: small, and the page sorts it, so each caller should get its own copy. (c) cache_resource: large, read-only, shared. If you said cache_data for (c), think about what copying a 260,000-row table on every rerun costs on an old laptop.

A4. Honesty: a curve fitted on data that includes the match would partly "know" the result, so the swings it shows would be flattered (Chapter 20's leakage demonstration, Brier 0.0185 on a random split v 0.1933 split by match, is the extreme version). Next season: the page will be used on matches the model has never seen, so the only accuracy that matters is out-of-time accuracy, and fitting on earlier seasons is the rehearsal for that.

A9. The running server returned its page, but the browser capture fired when the page's skeleton loaded, before Streamlit's script had sent its charts over the connection. The chapter's figures are drawn by the same fig_* functions from the same cached results, so they are the same pictures, but calling them screenshots would claim something that did not happen. Labelling the method is the same discipline as labelling simulated data.

C1. Expect the model window to matter less in a match where neither side dominated early. Check your turning-points table for wickets in the first six overs, as in the final, and for any late-over boundaries; then compare the top batting WPA with the player of the match recorded in the matches table.

C2. In the IPL 2026 final, Bengaluru's positive WPA comes overwhelmingly from bowlers (Rasikh Salam +0.112, Bhuvneshwar Kumar +0.105, Hazlewood +0.064, Krunal Pandya +0.054) and much less from batters (Venkatesh Iyer +0.078, Kohli +0.073, David +0.008). In the WPL final, Bengaluru's positive WPA is dominated by one batter (Mandhana +0.659). A good interpretation says why: the IPL final was decided while Gujarat batted; the WPL final was decided during the chase.

C3. Report chases and ball states beside every slope. A slope from 30 chases has a wide uncertainty; a bootstrap over chases (resample whole matches, never single balls) gives an interval. Flag only a competition whose interval excludes 1.

C4. The final was played on 8 March 2026 at the Narendra Modi Stadium, Ahmedabad, so "India at home" is the default reading of the venue. Your number will differ from Chapter 24's 0.739 if your team sheets differ (the dashboard's default is each side's last XI, not the announced XI) or if your freeze date includes or excludes the semi-finals.

C5. The hard part is not the optimiser; it is keeping the layers apart. The value matrix belongs in a cached function keyed by team and season; the page only picks the team and draws the plan. Check bowling_plan.consecutive_violations on the plan you display: an optimal plan that breaks the Laws is not a plan.

C6. Run rate × 20 improves fastest as the innings shortens, because fewer balls remain to be projected. The chapter's season table already shows the gap narrowing from 15 runs after 6 overs (20.0 v 35.1) to 1.3 runs after 15 overs (12.0 v 13.3). Look for the over where the difference stops being distinguishable from zero given 71 innings, and say how you decided.

C7. Reproduction tests should pin the inputs (fitting window, seeds, number of simulations) as well as the expected output, or they test nothing. Put the tolerance in the test name or docstring so the next person knows why 0.002 and not 0.

D1. Chapter 19's states.py and Chapter 23's resources.py already handle 50-over innings (ERTable(300, ...)), and Chapter 5 defines the ODI phases. Crease has no ODI chase model; you would fit one with winprob.fit_wp on ODI states built the same way, with balls_left up to 300. Whether an era split is needed is an empirical question: Chapter 23 found ODI resource percentages moved only 1.15 points between eras while totals rose 20.4 runs, which suggests the scoring environment term may be enough, but test it out of time before deciding.

D2. match_model (with its draw model, Chapter 24), test_sim (Chapter 29) and declaration (Chapter 33) all produce win, draw and loss probabilities. Chapter 29's direct model beat its simulator for fourth-innings chases (Brier 0.2996 v 0.3178). A Test page should show three stacked bands (win, draw, loss) over the days, not one line, and should label the days "nominal", as Chapter 29 does.

D3. Agree to change presentation (round to 5 runs, use "k in n" phrasing, show the range as a shaded bar rather than two numbers). Do not agree to remove the range: after 10 overs the median missed IPL 2026 first innings by 16.7 runs on average, and a single number would hide that the real total fell outside even the 80% range in about one innings in five.

D5. Either answer can be defended. If the page stays, it must say on the page that in the IPL 2023–26 the favourite won 47.6% of matches out of time and that the 2026 re-test was 0.7% worse than a coin on Brier score, and it should show the probability as a range of reasonable settings (as 39.6 does) rather than one number.

E2. The back-test is the heart of the exercise. A drift monitor that would not have caught the 2023 IPL break (WP v0 under-rating chasers by 13.4 points, Chapter 9) with only 2023's data is not yet useful; tune its thresholds on earlier seasons, then judge it on 2023, never the other way round.