Instructor Notes — Chapter 2: The Golf Analytics Toolkit

Chapter 2 is the data chapter. It shows where every real number in the book comes from (ESPN's open JSON, flattened into seven Parquet tables), why the raw data cannot be trusted without checks (withdrawals that weren't, wrong winners, wrap-around seasons, multi-course events, phantom par 6s), and how the shot simulator produces honest SIMULATED data for everything ESPN cannot see. It also introduces the cast and the reader's shot and scorecard schema. It is the least glamorous chapter in Part I and the one that prevents the most errors later. Sell it that way.

Chapter text · Discussion guide

Learning Objectives

By the end of the chapter, students should be able to:

  1. Classify any number in the book as REAL (ESPN), SIMULATED (with a seed) or cited reference, and say what each can and cannot support.
  2. Describe the structure of ESPN's JSON (events → competitions → competitors → rounds → holes) and explain how par is derived as strokes minus the relative-to-par code.
  3. Identify the main data quirks by count and choose the right handling: corrected outcome columns, calendar year, course-round grouping, missing-value zeros.
  4. Use pandas groupby, validated merge and reshaping to build a hole-difficulty table and a wide scorecard for one event.
  5. Explain the difference between calibrating and validating the simulator, and why every simulated output carries a seed.
  6. Record a round in the shot schema and run validate_shots to catch chain breaks and unit slips.

Suggested Session Plan

75-minute session

Minutes Activity Notes
0–8 Hook: the 2023 Open's wrong winner The raw build names Shubhankar Sharma; Brian Harman won with 271. Ask: how could a data set get the winner wrong?
8–20 Three kinds of numbers; what's in ESPN's JSON Walk the tree. Stress what ESPN does not carry: shot locations, lies, clubs, wind, strokes gained by category.
20–35 The quirks, counted Pick four: WD/DQ relabelling, season vs year, multi-course events (the 3.08-stroke Farmers gap), driving-distance zeros.
35–50 Lab: the 2026 Masters end to end Run 04_masters_2026_end_to_end.py. Hole difficulty, the 12th's double-or-worse rate, McIlroy vs Scheffler.
50–62 The simulator and the cast Marcus's simulated double bogey on the water hole, then the 5,000-play distribution. Emphasise representative seeds.
62–72 The yardbook schema and validation Show one bad hole caught by the chain check (the "one bad hole in the export" Play the Shot).
72–75 Exit ticket "Name one ESPN quirk and the column or rule that fixes it."

50-minute variant. Assign sections 2.2–2.4 (the JSON and the fetcher) as reading and skip the fetcher's internals in class. Teach the quirks (15 minutes), the Masters lab (15), and the simulator and cast (15), and leave validation to the project checkpoint as homework.

Key Numbers to Emphasise

Number What it means Source
1,061 events, 2004-01-11 to 2026-11-23; 1,031 usable; 4,221 players The size of the real snapshot REAL, 03_snapshot_and_quirks.py
4,741 → 3,542 genuine WD/DQ (1,199 relabelled, mostly MDF) Why outcome columns must be the corrected ones REAL, 03
93 events where ESPN's season ≠ calendar year Why the book counts by year REAL, 03, 09
107 multi-course events; 3.08 strokes between the 2026 Farmers courses in R1–2 Why players are compared within course-rounds REAL, 05_multicourse_and_staggered.py
1,282 phantom par-6 rows before the label fix; 0 after (443 consensus corrections) Cross-checking derived pars against the course finds glitches REAL, 09_exercise_checks.py
6,825 of 67,509 player-stat rows with driving distance 0 or missing Zeros mean missing REAL, 03, 09
2026 Masters: McIlroy 276 (−12), Scheffler 277; 12th double-or-worse 5.5% The end-to-end example REAL, 04
Raw 1,085 MB → 8.1 MB of Parquet Why tidy tables matter REAL, 01_raw_json_tour.py
Marcus's hole: E(tee) 4.007, scored 6, SG −1.993 vs PGA TOUR The accounting identity on one hole SIMULATED, seed 7
5,000 plays: mean 5.486, P(water) 0.357, max 78 The tails of one hole SIMULATED, seed 2026
Calibration RMSE 0.035 over 31 cells The simulator's fit to Broadie's table SIMULATED, seeds 100–130
Cast 20-round means: Emma 72.35 … Walt 96.90 The six golfers' representative samples SIMULATED, cast default seeds
σ = 2.756; 30 rounds to pin a tour level to ±1 stroke The variance theme in one line REAL, round SD

Likely Misconceptions

"An official-looking API gives correct data." Students assume a big sports site's JSON is clean. Address it with the 2023 Open: the raw columns produced the wrong winner, and finishers were labelled as withdrawals because their hole-by-hole scorecards looked incomplete. Case Study 1 shows the cause: impossible to-par tags on 943 of the event's 8,352 hole records, which the first-pass build could not read. The fix is a habit, not a library: check totals across sources.

"A season is a year." ESPN's season wraps autumn events into the next season, so the November 2020 Masters falls in season 2021, which then holds six majors. Exercise A.6 and C.2 target this.

"Averages are averages." Driving-distance zeros mean "missing". In 2019, including them drops the mean from 294.5 to 258.5 yards. Have students compute it themselves (C.7) so they feel the size of the error.

"Simulated data is fake data." Reframe: the simulator is honest because it is labelled, seeded and rerunnable, and it is calibrated to a published baseline. Equally, warn against the opposite error: calibration is not validation, and a simulated number is never a real player's statistic.

"One play of a hole tells you how hard it is." Marcus's seed-7 double bogey is one draw. Over seeds 1–20 he found the water in 10 plays, and over 5,000 plays the mean was 5.486 with a 78 in the tail. Variance is the enemy of understanding.

"App strokes gained is tour strokes gained." Different apps use different baselines and category boundaries (exercise D.2). The pitfall box in section 2.7 makes the point.

The Lab

Run scripts from the chapter directory with python code/NN_name.py. Every script runs in about 1–12 seconds.

  1. 01_raw_json_tour.py — one raw scoreboard file, the tree structure, and the 1,085 MB → 8.1 MB compression.
  2. 02_build_rules.py — the slowest script (about 11 seconds); it scans all 1,050 raw weekly files. Look for the drop counts (cancelled 2020 events, empty records).
  3. 03_snapshot_and_quirks.py — the inventory and the quirk counts. This is the script to run if students see counts that differ from the text.
  4. 04_masters_2026_end_to_end.py — the pandas walkthrough. Look for hole 5 (+0.297) and hole 11 (+0.293) as the hardest, hole 8 (−0.376) as the easiest, and 0 par or sum mismatches over 290 rounds.
  5. 05_multicourse_and_staggered.py — the Farmers two-course gap and the staggered-start TOUR Championships (for example, 2024: Scheffler won at 264, third-best by strokes behind Morikawa's 262).
  6. 06_one_simulated_hole.py and 07_simulator_calibration.py — Marcus's hole shot by shot, then the calibration slice.
  7. 08_cast_and_schema.py — writes the CSV templates to code/templates/.
  8. 09_exercise_checks.py, case_study_01.py (the 2023 Open scorecards), case_study_02.py (Rosa's differentials), project_checkpoint.py (builds yardbook.rounds; writes to code/_checkpoint/).

Ask students to compare each script's printed numbers with the chapter. When they disagree, that is a teaching moment, not a failure (see the caveats below).

Assigning Exercises by Track

  • ⛳ Golfer: A.1, A.3, A.7, A.8, A.9, A.10; B.3, B.6, B.7; C.8 (enter one of your own holes); D.2.
  • 📊 Analyst: A.2, A.4, A.5, A.6; B.1, B.2, B.4, B.5, B.8; C.1–C.7; D.3, D.4; M.1–M.5; one of E.1–E.3.
  • 🏌️ Coach/Fitter: A.1, A.8, A.9, A.10; B.2, B.3, B.7, B.8; C.6, C.8; D.2; M.4.
  • 🎰 Betting/DFS: A.5, A.6, A.7; B.5, B.6; C.1, C.4, C.5; D.1, D.3, D.4; M.3; E.1. This track should not skip section 2.5; their models in Parts VI–VII depend on the corrected outcome columns.

Golfers can skip the fetcher (section 2.3) and the C exercises other than C.8.

Connections to Other Chapters

  • Chapter 1 supplied the flight model; M.1, M.2 and M.4 connect the two chapters' validation habits.
  • Chapter 10 builds strokes gained on the shot schema and the accounting identity introduced here, and adjusts for field strength (exercise C.5's answer points there).
  • Chapter 12 builds baselines from the simulator calibrated in section 2.8.
  • Chapter 14 develops the σ = 2.756 variance lesson and shows other cast seeds.
  • Chapter 18 returns to Marcus's water hole.
  • Chapter 31 covers the wider tour data ecosystem (ShotLink, DataGolf) in depth.
  • Appendix B documents the toolkit; Appendix C has the current data counts.

Data and Toolkit Caveats

  • Wrong-par events. Four events have wrong ESPN hole pars (Bay Hill 2004–06, Booz Allen 2005). They stay in strokes-gained work, because strokes gained never uses par, but must be excluded from to-par and hole-scoring analyses via events()['par_ok']. data.hole_scoring does this automatically. The chapter states the rule exactly: par_ok False, kept for strokes gained.
  • data.infer_cuts() in events with incomplete scorecards counts only complete-scorecard players. In the earlier build it reported 40 made cuts for the 2023 Open against the true 76 (the cut line, 145, was right); in the final build that event is complete and it reports 76. The three events that still fail quality_ok (2004 PGA, 2005 Shell Houston, 2019 RBC Canadian) are where to demonstrate it now. Use made_cut_fixed.
  • The simulator's drop loop. Water drops at the entry point with unchanged aim, so rare blow-up holes appear (the 78 with 38 drops in 5,000 plays). Capping at 15 strokes moves the mean only by 0.018. Use it as a lesson in looking at tails, not as a bug to hide.
  • Representative seeds. Each cast member's default seed was chosen as the 20-round sample closest to that golfer's long-run profile. When students use a default cast sample, they should say so; Chapter 14 shows what other seeds look like.
  • ARG boundary. Around-the-green means a non-putt shot starting within 30 yards of the green's edge. Call it "this book's (golfkit's) definition"; the PGA TOUR's exact boundary is not verified.
  • Tee times. The processed tables carry no tee times. A timestamp field appears in some raw round records (2016 and 2026 samples, not 2004 or 2010); exercise E.2 explores it. Don't let students treat it as a ready-made wave variable.
  • Polite fetching. Custom request-header strings got HTTP 403 responses; the fetcher uses Python's default. Remind students to use the endpoints modestly; the API is unofficial.
  • pandas and .attrs. Storing objects in DataFrame.attrs can crash concat; the module's report class is defined with eq=False to avoid it. Students extending yardbook.rounds should keep that.