Repository navigation
Conversation
_prep_X_ml builds one row per cell of the cumulative triangle, but _prep_w_ml built one weight per non-empty cell of the triangle it was given. On an incremental triangle with empty cells in its observed area the counts differ, and since casact#1637 TweedieGLM passes the weights on every fit, so the plain fit raised a sample_weight shape error. Fixes casact#1640 Developed with an AI assistant (Árbol, running Muse).
Pyright Type CompletenessView the full Project (full
Other symbols referenced but not exported by
Symbols without documentation:
Patch (exported symbols added or changed by this PR): 0.0% fully typed (0 / 1)
Patch symbol details
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1641 +/- ##
==========================================
+ Coverage 95.00% 95.03% +0.03%
==========================================
Files 100 100
Lines 6460 6460
Branches 819 819
==========================================
+ Hits 6137 6139 +2
+ Misses 204 203 -1
+ Partials 119 118 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| coef[name, drop] = model.model_.estimator_ml["model"].coef_ | ||
| for drop in (None, "2017Q2"): | ||
| np.testing.assert_allclose(coef["incremental", drop], coef["cumulative", drop]) | ||
| assert not np.allclose(coef["incremental", None], coef["incremental", "2017Q2"]) |
There was a problem hiding this comment.
should we be comparing coef["incremenetal", ...] and coef["cumulative", ...]?
There was a problem hiding this comment.
The loop just above this line already does that. It compares the incremental and cumulative coefficients for both drop settings. This line checks that dropping 2017Q2 changes the fit, because the loop would also pass if both fits ignored drop_valuation, as in #1619. I pushed a comment above it that says so. Would a different check read better to you?
(This comment was written with Árbol, an AI assistant, under my direction.)
The last assertion checks that drop_valuation changes the fit, so the incremental-to-cumulative comparison cannot pass with the drop ignored. Developed with an AI assistant (Árbol, running Muse).
Summary of Changes
DevelopmentML._prep_w_mlnow builds its weights fromX.incr_to_cum(), both the base mask and theTriangleWeightexclusions._prep_X_mlbuilds one row per cell of the cumulative triangle, so the weights now line up with those rows when an incremental triangle has empty cells inside its observed area. Since #1637TweedieGLMpasses the weights on every fit, so on such a triangle the plain fit failed withValueError: sample_weight.shape == (203,), expected (220,)!.test_incremental_triangle_with_empty_cellsfitsTweedieGLMtoprismreported counts at OYDQ, incremental and cumulative, with and withoutdrop_valuation="2017Q2", and checks that the incremental and cumulative coefficients match and that the drop changes them. It fails on main with the ValueError and passes with the change.Related GitHub Issue(s)
Closes #1640
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 and the test, ran the checks below and drafted this description.
Additional Context for Reviewers
Fits on
prismreported counts, summed over the index:TweedieGLMon mainBarnettZehnwirthon mainAt OYDQ the incremental fit with this change matches the cumulative fit and the plain incremental fit on c113fd9, before #1637, to 10 decimal places, with and without
drop_valuation="2017Q2".A first version changed only the base mask. It cleared the error but gave zero weight to the 17 empty cells, because
TriangleWeightstill marked them empty, and every coefficient moved (largest difference 0.467). The new test fails on that version.The
chainladder/developmenttests pass (172 passed), and ruff check and format are clean on the changed files.Submitter's Checklist
[FIX],[FEAT],[DOCS],[TST],[CHORE], or[BRK]).Reviewer's Checklist