Chapter 39 Notes — Capstone: Your Cricket Analytics Platform
Chapter link: Chapter 39 · Assessment: the Crease capstone rubric in Rubrics, §4
Overview and learning objectives
Chapter 39 is the capstone. It adds no module to project/crease/; it makes the package a product.
Students measure what they built (36 modules, 617 public functions and classes, 99.2% documented,
14,969 non-blank code lines, an import graph that is a DAG with 28 edges and a longest chain
batting_order -> live -> winprob -> impact). They wire it into a seven-page Streamlit dashboard,
project/app.py, built in three layers. Then they run one real match, the IPL 2026 final
(Gujarat Titans 155/8, Royal Challengers Bengaluru 161/5 in 18 overs), through six stages: data,
metrics, win probability, attribution, pre-match and live. They write a model card for each of seven
models, re-test five of them frozen before 2026, and protect the whole thing with 37 smoke tests and
reproduction tests.
The chapter's cricket question is "can you trust the number on the screen?" Its answer is "yes, to a stated degree, and here is the degree". The 2026 scorecard is the heart of it: WP v1 Brier 0.1062 v 0.2500 (57.5% better); live projection after 10 overs mean miss 16.7 v 24.0 runs for run rate × 20; player projection RMSE 13.93 v 20.19; tournament log score −1.873 v −2.303; and the IPL pre-match model 0.7% worse than a coin (Brier 0.2516 v 0.2500).
By the end of the chapter students should be able to:
- Inventory a Python package with
ast, draw its dependency graph, and say what a DAG and the longest import chain mean for testing. - Separate a dashboard into cached data and model functions, figure builders and page layouts, and
choose correctly between
st.cache_dataandst.cache_resource. - Run one match through the six-stage pipeline and interpret each output, including why Rasikh Salam (+0.112) out-WPAs Kohli (+0.073).
- Explain why two honest models disagree about the same match, naming the specific differences in evidence (Elo system, home term, team sheets).
- Write a model card with all six fields, scored out of time against a named naive baseline, and compute a skill score from it.
- Write a smoke test that asserts a cricket fact and a reproduction test that pins a published number with its inputs.
- Judge a forecasting system on many forecasts, not one (coverage tables, dependent "confident calls").
Where students struggle
- Analysis inside the page. The commonest design fault in submitted capstones. Students fit
models inside
page_*functions "to keep it together". Show 39.2's check question: speed, testability and leakage all break. - The two caches.
cache_datacopies,cache_resourceshares. Students put fitted models incache_data(slow pickling) or mutate a cached predictor withPredictor.update. The 260,000-row matchups table is the test case. - Season numbers read as predictions. Stage 2's SR+ table (Patidar 124.5, Kohli 106.9) includes the final itself. Students then say "the metrics predicted RCB". Only stage 5 is a forecast.
- "Kohli won the final." WPA is new enough to most students that Rasikh Salam's top figure looks like a bug. The point is that the chase began at 86.5% and was at 98.6% after six overs, so little probability was left to add.
- "Which model is right?" The pre-match model gave Gujarat 0.571; WP v1 gave Gujarat 0.406 at the first ball. Students want one to be wrong. Push them to name the assumption that separates them: home advantage at a final (about six points).
- Reading −0.7% as a bug to be fixed. Strong students try to tune the pre-match model until 2026 looks good. Bring back Chapter 24's ceiling: a model knowing every team's true strength calls only 54.3% of IPL matches.
- Judging on one outcome. "155 was inside the range every over, so the simulator is calibrated" and "Punjab at 95.6% missed, so the simulator is broken" are the same mistake. Use the coverage table (84.5% / 81.7% / 69.0%) and Case Study 2's dependent calls.
- Anchor D's decimals. The dashboard shows de Kock v off-spin at 115.5 (108.5–122.4) v 125.8 — the same as Chapter 11's settled figure, because both now run on the final styles table. A student quoting 115.8 (108.6–123.0) v 125.5 is working from notes made on an earlier version of the table.
- Environment. Streamlit installs are the main lab problem on Windows. The data and figure layers
run without it (
_cachefalls back tolru_cache), so most of the chapter still works. First page visits take 5–20 seconds.
Pacing
The chapter supports a 2–3 week capstone, not a single lecture. Plan one or two taught sessions and then supervised lab time.
50-minute session.
- 0–5: Live launch of streamlit run project/app.py on the IPL 2026 final.
- 5–15: 39.1 inventory and dependency graph; the three-layer rule (39.2).
- 15–30: Stages 3–4: the WP curve and the productive struggle ("who won it for Bengaluru?"), then WPA.
- 30–40: Stage 5's disagreement and stage 6's live line.
- 40–50: The 2026 scorecard (39.8); assign the model-card activity.
75-minute session. As above, plus the 15-minute live coding demo after the inventory, and a
10-minute walk through project/tests/test_smoke.py and the reproduction idea (39.9). Lab time:
budget a 90-minute lab for installing Streamlit, running code/project_checkpoint.py (about two
minutes cold) and getting every page to load; then weekly capstone labs.
Lecture outline
- Nusrat's launch and Wendell's "and if it's wrong?"
- Measuring the package: the DAG;
statesmost imported (4); nine standalone modules. - Seven pages, three layers; caching and pure functions;
AppTest(10 of 10 runs). - Stages 1–2: Manhattan and worm; SR+ as context, not forecast; Sundar's eye test.
- Stage 3: WP v1 fitted on 2,780 chases 2023–25; 0.594 for RCB at the first ball, 0.865 at the break.
- Stage 4: turning points (Sai Sudharsan 3.4, −0.090); WPA (Rasikh +0.112, Kumar +0.105, Kohli +0.073).
- Stage 5: five pre-match settings, 0.509–0.577; three reasons the models disagree.
- Stage 6: after 10 overs 63/3, median 164 (135–195) v run rate × 20 126; real 155.
- Model cards: six fields; the 2026 scorecard; reading both halves of Card 1 (slope 0.99 overall, 1.33 IPL).
- Testing: smoke (37 tests, ~3 s), headless pages, reproduction (0.865, 0.571, 0.154, 0.465).
- The other pages and the roadmap (R2 drift monitor, R3 women's first, R10 live bowling planner).
Live coding demo
Script: code/02_end_to_end.py (about 10 seconds).
- Run it unchanged. Expect: 295,732 IPL deliveries from 1,243 matches, 233 in the final; states for 9,117 men's T20 matches; WP v1 fitted on 2,780 chases (306,209 ball states); env_par 191.7; Elo GT 1579, RCB 1612. The checkpoint table should read P(GT) 0.406 at the first ball, 0.220 after 10 overs, 0.135 at the innings break. Top turning point: Sai Sudharsan c Kumar, 3.4, −0.090.
- Live change 1 (leakage): change the fit filter from
<= 2025to<= 2026, so the model has seen the final's season, and rerun. Ask the class to predict the direction before running. Don't promise a number; the lesson is that the curve now "knows" something it shouldn't, and that the dashboard'swp_model(gender, year)exists to make this impossible. - Live change 2: restore the filter and set
MID = "1535464"(Qualifier 2, Exercise C1). Read the top turning points aloud and ask who won the match, and when. - Close with
python project/tests/test_smoke.py: 37 passed, 0 failed, in about three seconds.
If Streamlit works on the teaching machine, finish in the browser: switch the Match Centre to the WPL 2026 final and point to the model label changing to the women's fit.
In-class activity — "The card review board"
Groups of three each get one of Cards 1, 2, 3 or 7 from 39.8 with the Known weaknesses and Do not use it for rows blanked out, plus the matching 2026 re-test line. Each group also gets a client: a broadcaster, a franchise analyst or a sports editor. Task (20 minutes): fill in the two blank rows for that client, using only numbers on the sheet. Then compare with the chapter. Good groups will find the IPL slope of 1.33 on Card 1, the 69% coverage after 15 overs on Card 3, the 54.3% ceiling on Card 2, and "never 'Team X will win the IPL'" on Card 7. Debrief on the pitfall: a card without failure modes is an advertisement.
Answers and teaching notes for key exercises
- A7. Purpose; training data and period; target; out-of-time evaluation against a naive baseline; known failure modes; what it must not be used for. The chapter argues the last two matter most to a coach, because they stop a number being used where it breaks.
- A10. Two Elo systems (WP v1's within-competition Elo had RCB 33 points ahead; the tuned IPL Elo had them 6 apart), the home term (worth about six points; WP v1 has none), and team sheets. A full answer is in Appendix I.
- B4. Range 0.509–0.577 (6.8 points); home worth 6.3 points with last sheets and 6.2 with announced sheets; team sheets about 0.5. Home advantage at a final is the assumption that matters.
- B7. After 15 overs, expected outside at 80% coverage is 14.2 of 71; observed about 22. Late ranges are too narrow, which matches Card 3. Note that one season is still modest evidence.
- B8. About 4 or 5 misses in 100 independent 4.4% forecasts. The 33 confident calls are the same team-seasons re-forecast at eight checkpoints, so Punjab's one miss is counted three times. Count each team-season once.
- D3. Agree to change presentation (rounding to 5 runs, "k in n" phrasing, a shaded bar). Refuse to remove the range: the median missed by 16.7 runs on average after 10 overs in 2026.
- D5. Either answer can be defended. If the page stays, it must show the 47.6% (2023–26) and the −0.7% re-test on the page, and a range of settings rather than one number.
- C5 is the best single test of the three-layer rule: the value matrix in a cached function, a
fig_bowling_planbuilder, and a page that only picks the team. Check the displayed plan withbowling_plan.consecutive_violations.
Assessment ideas
- The capstone itself, marked on the 50-point rubric in Rubrics, §4. Set three milestones: week 1, every page loads and the smoke tests pass; week 2, model cards drafted with an out-of-time test for each; week 3, a 10–15 minute demonstration of one real decision.
- Require at least three reproduction tests (Exercise C7) in every submission. They catch the "integration left to the last week" failure the rubric warns about.
- A written model card for one model the student added or changed, with a 2026 re-test and both halves filled in.
Format, gender and region diversity notes
- Case Study 1 belongs in class, not as reading. The WPL 2026 final (Mandhana 87 off 41, WPA +0.659; Wolvaardt 44 off 25; Rodrigues 57 off 37) shows the cost of a men's model used by mistake: 0.302 v 0.198 for Bengaluru at the innings break.
- Be explicit about the gaps: Crease has no women's team-sheet model (the women's pre-match page is pure Elo), and the Matchups page defaults to men. Roadmap item R3 (women's first) and Exercise E1 are good capstone choices.
- The chapter is T20-only. Exercises D1 (ODI win probability) and D2 (a three-outcome Test page) are the format-transfer work; assign one to every group.
- Regions: Anchor D is a South African batter; the World Cup page carries an assumed rating for Afghanistan because Cricsheet withholds its men's internationals; bowler type is known for only 24.2% of men's associate T20I balls. Nusrat built all of it on an old laptop in Dhaka, so a modest machine isn't a reason to skip the capstone.
Connections
- Charts and the scoreboard: Chapter 7.
- WPA and value as change in win probability: Chapter 9; WP v1 and calibration: Chapter 20.
- Matchups (Anchor D): Chapter 11; batting value (Anchor B): Chapter 13.
- Pre-match model and the IPL ceiling: Chapter 24; projections: Chapter 25; live projection: Chapter 27; tournament simulation: Chapter 28.
- The portfolio the capstone completes: Chapter 38.
- What to build next, and why the models will drift: Chapter 40.