-
Notifications
You must be signed in to change notification settings - Fork 103
docs: add ClarkLDF doctest examples #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,6 +54,61 @@ class ClarkLDF(DevelopmentBase): | |
| norm_resid_: Triangle | ||
| The "Normalized" Residuals of the model according to Clark. | ||
|
|
||
| Examples | ||
| -------- | ||
| Compare curve families when the selected growth curve materially affects | ||
| the fitted development pattern. The same triangle can be fit with the | ||
| default loglogistic curve or with the Weibull curve. | ||
|
|
||
| .. testsetup:: | ||
|
|
||
| import chainladder as cl | ||
|
|
||
| .. testcode:: | ||
|
|
||
| import numpy as np | ||
|
|
||
| tri = cl.load_sample("ukmotor") | ||
| m_log = cl.ClarkLDF(growth="loglogistic").fit(tri) | ||
| m_wei = cl.ClarkLDF(growth="weibull").fit(tri) | ||
| print(float(np.round(m_log.ldf_.values[0, 0, 0, 0], 3))) | ||
| print(float(np.round(m_wei.ldf_.values[0, 0, 0, 0], 3))) | ||
|
|
||
| .. testoutput:: | ||
|
|
||
| 1.917 | ||
| 1.912 | ||
|
|
||
| Provide exposure when the goal is a Cape Cod fit rather than a pure LDF | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| fit. Passing ``sample_weight`` changes ``method_`` to ``cape_cod`` and | ||
| estimates ``elr_``. | ||
|
|
||
| .. testcode:: | ||
|
|
||
| tri = cl.load_sample("ukmotor") | ||
| m = cl.ClarkLDF().fit(tri, sample_weight=tri * 0 + 1e7) | ||
| print(m.method_) | ||
| print(float(np.round(m.elr_.values[0, 0], 6))) | ||
|
|
||
| .. testoutput:: | ||
|
|
||
| cape_cod | ||
| 0.002002 | ||
|
|
||
| Pool similar segments before fitting when each individual triangle is too | ||
| sparse for separate curve parameters. Here line of business produces one | ||
| parameter set per ``LOB``. | ||
|
|
||
| .. testcode:: | ||
|
|
||
| clrd = cl.load_sample("clrd").groupby("LOB")[["IncurLoss"]].sum() | ||
| m = cl.ClarkLDF(groupby="LOB").fit(clrd) | ||
| print(m.theta_.shape) | ||
|
|
||
| .. testoutput:: | ||
|
|
||
| (6, 1) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| """ | ||
|
|
||
| def __init__( | ||
|
|
||
There was a problem hiding this comment.
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