Skip to content

fix and enhance utils.model_diagnostics (#913)#914

Open
henrydingliu wants to merge 1 commit into
mainfrom
#839_model_summary
Open

fix and enhance utils.model_diagnostics (#913)#914
henrydingliu wants to merge 1 commit into
mainfrom
#839_model_summary

Conversation

@henrydingliu
Copy link
Copy Markdown
Collaborator

@henrydingliu henrydingliu commented Jun 4, 2026

Summary of Changes

As we work our way through Friedland, the community agreed that we need a way to easily assemble exhibits together. Fortunately, John already created a model_diagnostics utility function.

  • fixed a bug where latest is the sum of cumulative values
  • added support for predicted triangles
  • fixed a bug where ibnr_ doesn't work on when groupby is specified
  • added ldf and cdf to output
    • to do this more seamlessly, migrated _align_cdf function from MethodBase to Triangle. _align_cdf did not need any information from the IBNR estimator and actually made more sense to be a triangle method
  • added tests and streamlined some existing tests
    • added error handling around missing sample_weight to benktander

Related GitHub Issue(s)

closes #839

Additional Context for Reviewers

  • I passed tests locally for both code (uv run pytest) and documentation changes (uv run jb build docs --builder=custom --custom-builder=doctest)

Note

Medium Risk
Changes affect a shared reporting helper and refactor CDF alignment used by several IBNR methods; fixes are behavior-changing for Latest/groupby outputs but are covered by new tests.

Overview
model_diagnostics is reworked so exhibit-style summaries are more accurate and flexible: Latest is built from incremental development (fixing cumulative sums), predicted Triangle inputs are supported, groupby no longer breaks IBNR, and LDF / CDF columns are added when not grouping (via pattern alignment).

The CDF alignment logic moves from MethodBase._align_cdf to Triangle.align_pattern, which _align_cdf now delegates to; non-pattern triangles raise ValueError.

Benktander predict now requires sample_weight, matching fit. Tests are consolidated (parametrized predict/weights) and extended for diagnostics, align_pattern, and groupby consistency.

Reviewed by Cursor Bugbot for commit bcb9d6b. Bugbot is set up for automated code reviews on this repo. Configure here.

* fix and enhance utils.model_diagnostics

* bugbot fix

* adding test

* bugbot fix

* bugbot fix

* bugbot fix and docstring

* more tests

* fixing test

* fixing test

* fixing test
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bcb9d6b. Configure here.

if groupby is not None:
out["IBNR"] = obj.ibnr_[col].groupby(groupby).sum()
else:
out["IBNR"] = obj.ibnr_[col]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Groupby IBNR Latest mismatch

Medium Severity

With groupby, Latest comes from a grouped copy of the data triangle while IBNR still flows through ibnr_, which subtracts a latest diagonal from ungrouped X_. Ultimate is aggregated separately, so exhibit rows can break IBNR = Ultimate - Latest even after summing ibnr_ by group.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bcb9d6b. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cursoragent are you sure? ibnr_ is a property, not a static value

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unable to authenticate your request. Please make sure to connect your GitHub account to Cursor. Go to Cursor

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.42%. Comparing base (25e1192) to head (bcb9d6b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #914      +/-   ##
==========================================
+ Coverage   88.16%   88.42%   +0.26%     
==========================================
  Files          87       87              
  Lines        4952     4969      +17     
  Branches      629      635       +6     
==========================================
+ Hits         4366     4394      +28     
+ Misses        443      436       -7     
+ Partials      143      139       -4     
Flag Coverage Δ
unittests 88.42% <100.00%> (+0.26%) ⬆️

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.

@henrydingliu
Copy link
Copy Markdown
Collaborator Author

Changes affect a shared reporting helper and refactor CDF alignment used by several IBNR methods; fixes are behavior-changing for Latest/groupby outputs but are covered by new tests.

This isn't true. The new align_ldf method is a direct copy/paste of the previous _align_cdf method. There is no behavior change.

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] cl.Model_Diagnostics() does not show the correct Latest

1 participant