Repository navigation
Add Week 8 regression lecture (Moneyball) and exercise - #15
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Week-08-Regression/Lecture-Regression-Moneyball.ipynbWeek-08-Regression/Exercise-DONT-EDIT-MAKE-COPY-Moneyball.ipynbWeek-08-Regression/data/baseball.csvWeek-08-Regression/data/enhanced_moneyball_analysis_1990_2010.csvWeek-08-Regression/images/brad-pitt.pngLecture
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:
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.
RS→runs_scored,OBP→on_base_percentage). The player data usesthe same names for shared columns.
.params,.pvalues,.rsquaredand RMSE one ata time, then use a
print_model_report()helper in place of the fullstatsmodels summary.
do_moneyballandeval_regressionare refactored to prepareX/yonce. A testing-data block that was mislabeled is fixed.
rest of the league.
and the runs-allowed section (now the exercise).
the 2002 prediction numbers.
Exercise
Students model runs allowed from opponents' OBP and SLG, the section spun
off from the lecture:
print_model_report.do_moneyballandeval_regression, so students writethe steps themselves (define X/y, fit OLS, train/test split).
random_statemeans every student gets the same testnumbers. Reference answers: R² 0.907 / RMSE 25.2 on all data; R² 0.851 /
RMSE 31.1 on the test set.
Exercise-DONT-EDIT-MAKE-COPYprefix so thehomework workflow finds it as the Week 8 template.
exercise/.Testing
plotly 6.7). The exercise was also run with a sample solution from an
exercise/subfolder.103).
extension (
ms-toolsai.jupyter-renderers).