Skip to content

[FIX] Pass alpha from TweedieGLM to TweedieRegressor - #1663

Merged
henrydingliu merged 3 commits into
casact:mainfrom
scks1:#1584-tweedieglm-alpha
Nov 18, 2026
Merged

henrydingliu merged 3 commits into
casact:mainfrom
scks1:#1584-tweedieglm-alpha

Conversation

@scks1

@scks1 scks1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

TweedieGLM stored alpha but built its TweedieRegressor without it, so every fit used scikit-learn's default penalty of 1.0. The change passes alpha=self.alpha to the regressor in glm.py.

The plot_glm_ldf gallery example now sets alpha=0, since the default penalty of 1.0 would keep its GLM factors from matching Development. With both changes the largest factor gap on genins drops from 0.00042 to 0.0000008. The docs build executes notebooks, so the stored plot output stays as it is.

test_alpha_reaches_regressor fits TweedieGLM(alpha=0) to ukmotor and checks that the regressor's alpha is 0. With alpha passed through, test_basic_odp_cl, test_sample_weight and test_alpha_reaches_regressor now fit with alpha=0 and use np.testing.assert_allclose with rtol=1e-5 on the ultimates against Chainladder, and the first and third also on ldf_ against Development. Before, they bounded the largest ultimate gap divided by the latest diagonal at 1e-2 or 1e-3. The largest measured relative gap is 5.7e-07 on genins and 1.4e-07 on ukmotor. All three fail on main and pass with the change.

Related GitHub Issue(s)

Closes #1584

AI/LLM Usage

This change was made with Árbol, an AI assistant running on Muse, working under my direction. It found the bug, wrote the change, the test and the gallery edit, ran the checks below and drafted this description.

Additional Context for Reviewers

  1. Values on main and with the change, C(development) + C(origin), log link, power 1:
Triangle Fit 12-24 factor Total ultimate
ukmotor Development and Chainladder 1.8892 104,328
ukmotor TweedieGLM(alpha=0) on main 1.9040 105,538
ukmotor TweedieGLM(alpha=0) with the change 1.8892 104,328
genins Development and Chainladder 3.4906 53,038,946
genins TweedieGLM(alpha=0) on main 3.4910 53,041,750
genins TweedieGLM(alpha=0) with the change 3.4906 53,038,955

The default stays alpha=1.0, so a fit that omits alpha gives the same numbers as before.

  1. With the change, TweedieGLM(design_matrix=..., alpha=0, max_iter=1000) reproduces the DevelopmentML(..., TweedieRegressor(alpha=0, ...)) fits in [DOCS] Show origin-varying ldf_ from DevelopmentML in the user guide #1621 exactly on genins, for both formulas in that example.

  2. [CHORE] Change all project references from chainladder-python to chainladder (#1595) #1656 also edits test_glm.py, and the two branches merge without conflict.

On main at a59efc9, chainladder/development/tests/test_glm.py gives 5 failed and 6 passed, and with the change 11 passed. chainladder/development gives 173 passed with the change, and ruff check and format are clean on the changed files.

Submitter's Checklist

  • I have reviewed and am adhering to the standards outlined in the project Governing Doc.
  • The PR subject title summarizes the changes, with one proper prefix ([FIX], [FEAT], [DOCS], [TST], [CHORE], or [BRK]).
  • I am a human (not a bot), and this PR form is written by a human.

Reviewer's Checklist

  • The implementation addresses the associated issue(s).
  • The implementation is appropriate, maintainable, and follows ARCHITECTURE.md.
  • PR subject title has the proper prefix and the subject is appropriate.
  • Relevant issue(s) are linked.
  • AI/LLM usage is disclosed and appropriate.
  • Documentation and tests are appropriate.
  • CI tests passed, or any failures are acceptable.
  • Leave a comment with the final recommendation (e.g. approve as is, request a secondary review, or flag an area for more review).

TweedieGLM stored alpha but built its TweedieRegressor without it, so
every fit used scikit-learn's default penalty of 1.0. With alpha passed,
TweedieGLM(alpha=0) on ukmotor reproduces the chain ladder ultimates.

Closes casact#1584.

Developed with an AI assistant (Árbol, running Muse).
TweedieGLM defaults to alpha=1.0, so the unpenalized ODP fit that
matches chain ladder needs alpha=0 now that TweedieGLM passes alpha
to TweedieRegressor.

Developed with an AI assistant (Árbol, running Muse).
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Pyright Type Completeness

View the full pyright --verifytypes output for this commit

Project (full chainladder package, at this PR's head): 18.1% of exported symbols fully typed (303 / 1678)

Known Ambiguous Unknown Total
Project (head) 303 96 1279 1678

Other symbols referenced but not exported by chainladder: 24

Known Ambiguous Unknown Total
Other (head) 11 1 12 24

Symbols without documentation:

  • Functions without docstring: 329
  • Functions without default param: 0
  • Classes without docstring: 10

Patch (exported symbols added or changed by this PR): 0.0% fully typed (0 / 1)

Known Ambiguous Unknown Total
Patch 0 0 1 1
Patch symbol details
Symbol Status Change
chainladder.development.tests.test_glm.test_alpha_reaches_regressor ❌ unknown new

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.03%. Comparing base (a59efc9) to head (52b786e).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1663   +/-   ##
=======================================
  Coverage   95.03%   95.03%           
=======================================
  Files         100      100           
  Lines        6460     6471   +11     
  Branches      819      819           
=======================================
+ Hits         6139     6150   +11     
  Misses        203      203           
  Partials      118      118           
Flag Coverage Δ
unittests 95.03% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

glm = cl.TweedieGLM(alpha=0).fit(ukmotor)
assert glm.model_.estimator_ml.named_steps["model"].alpha == 0
assert (
abs(

@henrydingliu henrydingliu Nov 18, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see this testing pattern pop up in this test file. it feels less precise than most other tests in the repo. i wonder if we can tighten up all the abs(relative diff) tests now alpha is being fed in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 52b786e. test_basic_odp_cl, test_sample_weight and test_alpha_reaches_regressor now fit with alpha=0 and use np.testing.assert_allclose with rtol=1e-5. Each compares the ultimates with Chainladder, and the first and third also compare ldf_ with Development. Before, the bound on the largest ultimate gap over the latest diagonal was 1e-2 for the two genins tests and 1e-3 for ukmotor.

The largest relative gap I measured is 5.7e-07 on genins and 1.4e-07 on ukmotor, with or without the unit sample weight, so 1e-5 leaves room for solver noise across platforms. A higher max_iter or a smaller tol doesn't change either value. On main all three tests fail, with gaps of 1.2e-04 in the factors and 2.0e-04 in the ultimates on genins.

(This comment was written with Árbol, an AI assistant, under my direction.)

test_basic_odp_cl, test_sample_weight and test_alpha_reaches_regressor
compared ultimates through max(|difference| / latest diagonal) with
bounds of 1e-2 and 1e-3. Now that TweedieGLM passes alpha through, the
three tests fit with alpha=0 and use np.testing.assert_allclose with
rtol=1e-5 on the ultimates, and the genins and ukmotor tests also on
ldf_ against Development. The largest measured relative differences
are 5.7e-07 on genins and 1.4e-07 on ukmotor. On main all three fail.

Developed with an AI assistant (Árbol, running Muse).
@henrydingliu
henrydingliu merged commit cc3335c into casact:main Nov 18, 2026
11 checks passed
scks1 added a commit to scks1/chainladder-python that referenced this pull request Nov 18, 2026
With the casact#1584 fix merged in casact#1663, TweedieGLM passes alpha to its
regressor, so the example no longer needs a hand-built DevelopmentML
pipeline. Both genins fits and the ultimate ratios are unchanged.

Developed with an AI assistant (Árbol, running Muse).
henrydingliu pushed a commit that referenced this pull request Nov 19, 2026
With the #1584 fix merged in #1663, TweedieGLM passes alpha to its
regressor, so the example no longer needs a hand-built DevelopmentML
pipeline. Both genins fits and the ultimate ratios are unchanged.

Developed with an AI assistant (Árbol, running Muse).
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.

[BUG] TweedieGLM never passes alpha to TweedieRegressor

2 participants