Skip to content

Solve parts (b) and (c) of the Wage polynomial exercise; scale age in the Python CV - #1399

Merged
d-morrison merged 7 commits into
mainfrom
claude/gam-applied-solutions
Dec 3, 2026
Merged

d-morrison merged 7 commits into
mainfrom
claude/gam-applied-solutions

Conversation

@d-morrison

@d-morrison d-morrison commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Before: exr-wage-polynomial-cv asks for a confidence band (b) and a cross-validated step function (c), but its solution only did (a). The Python solution passed raw age**10 to least squares, which is ill-conditioned, and its folds were not shuffled.

After: the R and Python solutions both do (a), (b) and (c). Python standardizes age before taking powers, as the R solution's poly() does, and uses shuffled folds. R and Python pick the same answers: degree 9 and 7 cut-points.

How: only _subfiles/generalized-additive-models/_exr-gams-applied.qmd changes. I rendered chapters/generalized-additive-models.qmd to HTML with no warnings; the R output reads "CV-selected degree: 9" and "CV-selected number of cut-points: 7". The Python chunk is not run in the rme render (eval: false), so I ran it locally against the same Wage data and got the same two values. typos is clean on the file. Part of the drift audit in Morrison-Lab/lds#1214, which listed these as follow-ups to rme#1393.

Differences from the source (ISLRv2 Applied 6):

Item Kind Decision
Solution omitted (b) and (c) accidental added
Python PolynomialFeatures on raw age accidental standardize first
Step-function cut-points counted as intervals clarified K cut-points make K + 1 intervals, stated in the text

Update (2026-12-02), after merging main (185 commits behind):

  • "intervals" in the step-function solution now links to its definition on the mcs site, because main's term-link check knows the term.
  • check-one-div-per-subfile, now on main, fails a touched subfile with more than one top-level div.
    So exr-wage-polynomial-cv and exr-backfitting each move, with their solutions and unchanged, into their own subfiles: _exr-wage-polynomial-cv.qmd and _exr-backfitting.qmd.
    _exr-gams-applied.qmd keeps the source notes and the two headings and includes the new files.
  • The review of that commit flagged the Wage exercise as one exercise with three asks.
    So it is now three exercises, each with its own solution and subfile:
    • exr-wage-polynomial-cv (choose the degree by CV; keeps the old id), in _exr-wage-polynomial-cv.qmd;
    • exr-wage-poly-band (fit the chosen degree with a 95% band), in _exr-wage-poly-band.qmd;
    • exr-wage-step-cv (choose the cut-points by CV), in _exr-wage-step-cv.qmd.
      Each later exercise names the Wage data and cites the exercise it builds on.
      The code is unchanged, only split between the three solutions.
  • The reworded lines now link their terms (outcome, predictor, cross-validation, degree, bins and others), as main's term-link check requires.
  • The polynomial link pointed at mds/algebra-exponentials.html#def-polynomial, which no longer has that anchor; it now points at algebra-polynomials.html.
  • A short paragraph by the Python step-function code explains the equal-width bins: they match R's cut() and the ISLR lab (§7.8.1), and quantile bins are the alternative.
  • I rendered the chapter again after each change; the R output still reads degree 9 and 7 cut-points, the new cross-references resolve, and lint and spelling are clean.

Generated by Claude Code


Generated by Claude Code

… in the Python CV

The exercise asks for a confidence band (b) and a cross-validated step function (c),
but the solution only did (a). The Python solution also fed raw age**10 to least squares,
which is ill-conditioned; it now standardizes age first, as the R solution's poly() does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nh61VJUp2V6tGvtkZ3BZKF

Copy link
Copy Markdown
Collaborator Author

link-checker / link-checker failed on its only error: [503] https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols (at 197:34) in chapters/intro-to-R.qmd. This PR does not touch that file, so the failure is an external outage of oeis.org, not this change. I am using the one allowed re-run of the failed job now.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

The re-run of link-checker / link-checker failed again on the same oeis.org 503. A fix already exists in rme#1398, which excludes that one URL in lychee.toml. I am not copying it into this PR, because rme keeps .github/CI/config changes out of content PRs. Once rme#1398 merges I will merge main into this branch so the check runs against it.


Generated by Claude Code

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Nh61VJUp2V6tGvtkZ3BZKF
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Main's term-link check now knows "interval" from the mcs prerequisite
site, so link its first use in the exr-wage-polynomial-cv solution.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGiaktxMs3jUmMZBCv
@github-actions

This comment has been minimized.

check-one-div-per-subfile (now on main) fails a touched subfile that holds
more than one top-level div. Move exr-wage-polynomial-cv and exr-backfitting,
each with its solution, into their own subfiles, unchanged, and include them
from _exr-gams-applied.qmd under the same headings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGiaktxMs3jUmMZBCv
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

The review of 9764263 flagged exr-wage-polynomial-cv as one exercise with
three asks. Give each ask its own exercise, solution and subfile:
exr-wage-polynomial-cv (CV degree; keeps the old id), exr-wage-poly-band
(fit with a 95% band) and exr-wage-step-cv (CV cut-points). Each later
exercise names the data and cites the earlier one it builds on.

Also link the terms these reworded lines use, fix the polynomial link (the
mds definition moved to algebra-polynomials.html), and explain the
equal-width bins next to the Python code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWgYrGiaktxMs3jUmMZBCv
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Claude finished review — View run


I reviewed head bd5412eec69522491d9f1052b2504215f5e0cf0b. The one blocking finding from the last round is fixed, and I found no new blocking issues.

Earlier findings

  • _subfiles/generalized-additive-models/_exr-wage-polynomial-cv.qmd:5 (the three-part exercise, rule 7): fixed by commit bd5412e.
    • exr-wage-polynomial-cv now asks only for the CV-chosen degree and the CV-error plot, lines 3-8.
    • Part (b) is its own #exr-wage-poly-band with #sol-wage-poly-band, in _exr-wage-poly-band.qmd.
    • Part (c) is its own #exr-wage-step-cv with #sol-wage-step-cv, in _exr-wage-step-cv.qmd.
    • exr-wage-poly-band now says "the degree $d^*$ that cross-validation chose in @exr-wage-polynomial-cv", as I suggested.
    • exr-wage-step-cv links back to the same exercise for the data.
    • The earlier verdict, "Needs more work", is at Solve parts (b) and (c) of the Wage polynomial exercise; scale age in the Python CV #1399 (comment).

What changed in 97642633..bd5412ee

  • _exr-gams-applied.qmd: it includes the three Wage exercises in order, and each one after the first has a {{< slidebreak >}} before it. The first include keeps its reason comment for the omitted slidebreak, because the heading shares the slide with the div.
  • Moved bodies: the R and Python code in _exr-wage-poly-band.qmd and _exr-wage-step-cv.qmd matches the code the earlier rounds verified. The one change is Wage_cut → wage_cut, and that fix stays in place.
  • Links: I fetched the pages the new mds and mcs links point to. mds/algebra-polynomials.html has #def-polynomial and #def-polynomial-degree, and mcs/sets.html has #def-interval. The #def-polynomial-regression target exists at _sec_polynomial.qmd:11, so the link in _exr-wage-poly-band.qmd:6 resolves.
  • Math: the only math is inline $d^*$, $K^*$, $K$ and $K + 1$. No macro finding applies.

Suggestions (non-blocking)

  • _exr-wage-step-cv.qmd:17: "so cut(age, K + 1) makes it" leaves "it" without a referent. Consider "so cut(age, K + 1) creates those intervals".
  • _exr-wage-poly-band.qmd:3: "Use the Wage data" has an antecedent only in the earlier exercise, which the next sentence links. Writing "Use the Wage data from @exr-wage-polynomial-cv", as exr-wage-step-cv does, would make this opener self-contained.
  • Cross-exercise state: the R and Python solutions in sol-wage-poly-band and sol-wage-step-cv reuse best_d, age_grid, X, y and folds from earlier solutions. This works because the page is rendered in order, but the split exercises would break if someone reordered or excluded one of them.

Verdict

Ready for merge. The earlier multi-part-exercise finding is fixed, and I found no new blocking issues in bd5412e.

Structured Review Data (JSON)
{
  "schema_version": "1.1",
  "reviewer": "claude",
  "commit_sha": "bd5412eec69522491d9f1052b2504215f5e0cf0b",
  "verdict": "CLEAN",
  "findings": [],
  "detailed_assessment": "Commit bd5412e splits the three-part Wage exercise into exr-wage-polynomial-cv, exr-wage-poly-band and exr-wage-step-cv, each with its own solution subfile; links resolve and the code is unchanged from earlier verified rounds.",
  "holistic_assessment": "The split resolves the prior one-ask-per-exercise finding, the parent file includes the subfiles in order with slidebreaks, and the only remaining concerns are minor wording suggestions and the cross-exercise state the solutions share."
}

I read the PR's mergeability just now: mergeable is MERGEABLE, so there are no conflicts. mergeStateStatus is BLOCKED, which means a branch-protection requirement (a required check or review) has not been met yet. I did not check which one.

My review is unchanged. Head bd5412eec69522491d9f1052b2504215f5e0cf0b has no blocking findings, and the earlier multi-part-exercise finding is fixed.

Verdict

Ready for merge on content and conflicts. The BLOCKED merge state means the PR cannot merge until the pending protection requirement is satisfied.

Structured Review Data (JSON)
{
  "schema_version": "1.1",
  "reviewer": "claude",
  "commit_sha": "bd5412eec69522491d9f1052b2504215f5e0cf0b",
  "verdict": "CLEAN",
  "findings": [],
  "detailed_assessment": "Commit bd5412e splits the three-part Wage exercise into exr-wage-polynomial-cv, exr-wage-poly-band and exr-wage-step-cv, each with its own solution subfile; links resolve and the code is unchanged from earlier verified rounds.",
  "holistic_assessment": "The split resolves the prior one-ask-per-exercise finding, the parent file includes the subfiles in order with slidebreaks, and the only remaining concerns are minor wording suggestions and the cross-exercise state the solutions share."
}

Reviewed commit: bd5412e

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

💰 Cost: $0.3473 (review) — run

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2
🚀 Preview available at: https://Morrison-Lab.github.io/rme/pr-preview/pr-1399/

Built to branch gh-pages at 2026-12-02 19:46 UTC.

@d-morrison
d-morrison merged commit ca2ec3e into main Dec 3, 2026
44 checks passed
@d-morrison
d-morrison deleted the claude/gam-applied-solutions branch December 3, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants