Skip to content

docs: add ClarkLDF doctest examples#802

Open
EKtheSage wants to merge 4 commits into
casact:mainfrom
EKtheSage:docs/704-clarkldf-doctest-example
Open

docs: add ClarkLDF doctest examples#802
EKtheSage wants to merge 4 commits into
casact:mainfrom
EKtheSage:docs/704-clarkldf-doctest-example

Conversation

@EKtheSage

@EKtheSage EKtheSage commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary: Add focused ClarkLDF Sphinx doctest examples and make the numeric comparison robust to small platform/dependency drift by rounding the displayed LDF values. Split from the larger #786 work and intentionally excludes .github/workflows/sync-main-to-docs.yml. Refs #704


Note

Low Risk
Documentation-only change to the class docstring; no runtime or API behavior changes.

Overview
Adds a new Examples section to the ClarkLDF class docstring in clark.py, with three Sphinx doctest blocks and narrative aimed at actuaries.

The first example fits loglogistic vs weibull on ukmotor, prints rounded LDFs and G_(240) to show tail sensitivity, and explains curve choice. The second shows Cape Cod via sample_weight and documents method_ / elr_. The third uses groupby="LOB" on the clrd sample to pool thin triangles and print omega_ / theta_.

There are no changes to estimator logic or public API—documentation and doctest coverage only.

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

@codecov

codecov Bot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.79%. Comparing base (b24f209) to head (0377b04).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #802   +/-   ##
=======================================
  Coverage   88.79%   88.79%           
=======================================
  Files          89       89           
  Lines        5060     5060           
  Branches      646      646           
=======================================
  Hits         4493     4493           
  Misses        423      423           
  Partials      144      144           
Flag Coverage Δ
unittests 88.79% <ø> (ø)

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

i went back and read a few pages from the pandas doc. a lot of them starts with a description of what a user is looking to accomplish, then goes through the details. but if we take the most curt example docstring I found on pandas, which is the xs function, the basic flow is still "user goal" -> "code implementation", rather than "in depth description of a parameter" -> "code implementation". could we do something similar with our examples? so instead of explaining the parameter, describe an issue then offer the parameter as the solution.

@EKtheSage EKtheSage force-pushed the docs/704-clarkldf-doctest-example branch from e6eee62 to 9fc573e Compare May 17, 2026 04:20
Comment thread chainladder/development/clark.py Outdated
1.917
1.912

Provide exposure when the goal is a Cape Cod fit rather than a pure LDF

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

awkward phrasing. the intentionality of the user is to use cape cod. to use cape cod, the user can pass in a weight vector without additional parameters in the clarkldf transformer.

Comment thread chainladder/development/clark.py Outdated

.. testoutput::

(6, 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the example text makes a claim about individual triangles being too sparse to fit. the actual code doesn't really make that apparent, or even show the results at all

print(float(np.round(m_wei.ldf_.values[0, 0, 0, 0], 3)))

.. testoutput::

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

too close to be a worthy choice of an example

@kennethshsu

Copy link
Copy Markdown
Collaborator

@EKtheSage are you interested in finishing up this PR?

Ethan Kang added 2 commits June 11, 2026 14:49
- compare loglogistic and weibull fits on the full ldf_ pattern and on
  percent of ultimate emerged at 240 months to show that the curve
  choice drives the tail even when in-triangle factors nearly match
- demonstrate Clark Cape Cod by passing a premium vector as
  sample_weight and printing the fitted expected loss ratios by line
- show that clrd holds 775 company triangles and use groupby to pool
  them into one growth curve fit per line of business
@EKtheSage

Copy link
Copy Markdown
Contributor Author

@henrydingliu all three comments are addressed. The curve comparison now prints full ldf_ patterns plus the percent of ultimate emerged at 240 months (85% loglogistic versus 99% weibull), so the difference is material. The Cape Cod example now simply passes a premium vector as sample_weight on clrd data and prints the fitted ELRs by line. The groupby example shows the 775 company triangles being pooled into one curve fit per LOB with the fitted parameters. Main is merged in as well.

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.

3 participants