Skip to content

Add Week 8 regression lecture (Moneyball) and exercise - #15

Merged
craigsakuma merged 1 commit into
mainfrom
week08
Oct 19, 2026
Merged

craigsakuma merged 1 commit into
mainfrom
week08

Conversation

@craigsakuma

Copy link
Copy Markdown
Collaborator

Summary

Adds the Week 8 linear regression lesson, built around the 2002 Oakland A's
"Moneyball" story, plus the week's exercise. The lecture is adapted from the
2025 version and reworked to fit one class session and to be easier to follow
for students who don't know baseball.

Files

File Purpose
Week-08-Regression/Lecture-Regression-Moneyball.ipynb Lecture notebook
Week-08-Regression/Exercise-DONT-EDIT-MAKE-COPY-Moneyball.ipynb Week 8 exercise template
Week-08-Regression/data/baseball.csv Team-season data (1962–2012)
Week-08-Regression/data/enhanced_moneyball_analysis_1990_2010.csv Player-season data with salaries
Week-08-Regression/images/brad-pitt.png Image asset

Lecture

Structure: Intro → Part 1: What makes a team score runs? → Part 2: Finding
undervalued players → Part 3: How many wins to make the playoffs? → Part 4:
Building a playoff roster.

Changes from the 2025 version:

  • Intro: title cell, the ISBE workflow (Inspect, Select, Build, Evaluate) as
    a reference table, and a 60-second baseball primer for non-fans. The plan is
    written as questions, so it doesn't give away the Part 4 payoff.
  • Readable data:
    • Abbreviated columns are renamed with a dictionary and lower-cased (e.g.
      RS → runs_scored, OBP → on_base_percentage). The player data uses
      the same names for shared columns.
    • Data prep is split into one step per cell.
  • Simpler model output:
    • Students first pull out .params, .pvalues, .rsquared and RMSE one at
      a time, then use a print_model_report() helper in place of the full
      statsmodels summary.
    • do_moneyball and eval_regression are refactored to prepare X/y
      once. A testing-data block that was mislabeled is fixed.
  • Interactive charts:
    • All charts use Plotly.
    • Adds a 2002 A's vs Yankees OBP-vs-salary chart, with team colors over the
      rest of the league.
  • Shorter:
    • Removed: the assumption-checking section, the logistic regression bonus,
      and the runs-allowed section (now the exercise).
    • Part 4's model rebuilding is condensed into a diagram of the method plus
      the 2002 prediction numbers.
  • Fixes:
    • Corrected a misleading data-leakage hint.
    • Fixed comments that referred to the wrong variables.

Exercise

Students model runs allowed from opponents' OBP and SLG, the section spun
off from the lecture:

  • Provided: the data loading and column renaming, the data dictionary, and
    print_model_report.
  • Not provided: do_moneyball and eval_regression, so students write
    the steps themselves (define X/y, fit OLS, train/test split).
  • Structure: five headed step cells with short hints.
  • Grading: a fixed random_state means every student gets the same test
    numbers. Reference answers: R² 0.907 / RMSE 25.2 on all data; R² 0.851 /
    RMSE 31.1 on the test set.
  • Auto-review: named with the Exercise-DONT-EDIT-MAKE-COPY prefix so the
    homework workflow finds it as the Week 8 template.
  • Data path: loads from either the week folder or exercise/.

Testing

  • Both notebooks run top to bottom with no errors (Python 3.14, pandas 3.0,
    plotly 6.7). The exercise was also run with a sample solution from an
    exercise/ subfolder.
  • Final prediction checks out: ~100 wins predicted for the 2002 A's (actual:
    103).
  • Charts need a Plotly renderer. In VS Code that's the Jupyter Renderers
    extension (ms-toolsai.jupyter-renderers).

@craigsakuma
craigsakuma merged commit d010ab4 into main Oct 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant