From 0335bfc4c019b9db392055ee90ef48328538a14c Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Sat, 14 Nov 2026 22:37:55 +0000 Subject: [PATCH 1/2] [DOCS] Show origin-varying ldf_ from DevelopmentML in the user guide MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an "Origin-varying patterns" subsection after PatsyFormula. The ODP cross-classified GLM gives one identical row of ldf_ per origin, equal to Development's pattern; an origin:I(development / 12) term gives each origin its own factors, and Chainladder applies each origin's own row. Developed with an AI assistant (Árbol, running Muse). --- docs/user_guide/development.ipynb | 376 ++++++++++++++++++++++++++++++ 1 file changed, 376 insertions(+) diff --git a/docs/user_guide/development.ipynb b/docs/user_guide/development.ipynb index edebee380..f0a0b43f6 100644 --- a/docs/user_guide/development.ipynb +++ b/docs/user_guide/development.ipynb @@ -7383,6 +7383,382 @@ "```" ] }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "origin-varying-intro", + "metadata": {}, + "source": [ + "### Origin-varying patterns\n", + "\n", + "`DevelopmentML` predicts every cell of the `Triangle`, so its `ldf_` has one row per\n", + "origin period, where `Development` has a single row. Whether those rows differ\n", + "depends on the model. The over-dispersed Poisson (ODP) cross-classified GLM, fit to\n", + "incrementals with a log link and the design matrix `C(development) + C(origin)`,\n", + "gives the same pattern for every origin, and that pattern is the volume-weighted\n", + "chainladder {cite}`taylor2016`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "origin-varying-odp", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
12-2424-3636-48
20013.49101.74701.4570
20023.49101.74701.4570
20033.49101.74701.4570
20043.49101.74701.4570
20053.49101.74701.4570
20063.49101.74701.4570
20073.49101.74701.4570
20083.49101.74701.4570
20093.49101.74701.4570
20103.49101.74701.4570
" + ], + "text/plain": [ + " 12-24 24-36 36-48\n", + "2001 3.491 1.747 1.457\n", + "2002 3.491 1.747 1.457\n", + "2003 3.491 1.747 1.457\n", + "2004 3.491 1.747 1.457\n", + "2005 3.491 1.747 1.457\n", + "2006 3.491 1.747 1.457\n", + "2007 3.491 1.747 1.457\n", + "2008 3.491 1.747 1.457\n", + "2009 3.491 1.747 1.457\n", + "2010 3.491 1.747 1.457" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from sklearn.linear_model import TweedieRegressor\n", + "\n", + "genins = cl.load_sample(\"genins\")\n", + "\n", + "\n", + "def odp_glm(formula):\n", + " # Unpenalized ODP GLM on incrementals with a patsy design matrix\n", + " return cl.DevelopmentML(\n", + " Pipeline(\n", + " steps=[\n", + " (\"design_matrix\", cl.PatsyFormula(formula)),\n", + " (\n", + " \"model\",\n", + " TweedieRegressor(\n", + " power=1, link=\"log\", alpha=0, fit_intercept=False, max_iter=1000\n", + " ),\n", + " ),\n", + " ]\n", + " ),\n", + " y_ml=\"values\",\n", + " )\n", + "\n", + "\n", + "cross_classified = odp_glm(\"C(development) + C(origin)\").fit(genins)\n", + "cross_classified.ldf_.iloc[..., :3].round(3)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "origin-varying-drift", + "metadata": {}, + "source": [ + "Every row matches `cl.Development().fit(genins).ldf_`. Adding an\n", + "`origin:I(development / 12)` term lets the development pattern drift from one origin\n", + "year to the next, so each origin gets its own age-to-age factors. Here the factors\n", + "rise for later origins." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "origin-varying-fit", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
12-2424-3636-48
20013.43201.72701.4430
20023.44601.73301.4480
20033.46001.73801.4520
20043.47401.74301.4570
20053.48801.74901.4610
20063.50201.75401.4660
20073.51601.76001.4710
20083.53101.76601.4750
20093.54501.77101.4800
20103.56001.77701.4850
" + ], + "text/plain": [ + " 12-24 24-36 36-48\n", + "2001 3.432 1.727 1.443\n", + "2002 3.446 1.733 1.448\n", + "2003 3.460 1.738 1.452\n", + "2004 3.474 1.743 1.457\n", + "2005 3.488 1.749 1.461\n", + "2006 3.502 1.754 1.466\n", + "2007 3.516 1.760 1.471\n", + "2008 3.531 1.766 1.475\n", + "2009 3.545 1.771 1.480\n", + "2010 3.560 1.777 1.485" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "drifting = odp_glm(\"C(development) + C(origin) + origin:I(development / 12)\").fit(\n", + " genins\n", + ")\n", + "drifting.ldf_.iloc[..., :3].round(3)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "origin-varying-methods", + "metadata": {}, + "source": [ + "`Chainladder` applies each origin's own row of `ldf_`: an\n", + "origin's ultimate is its latest diagonal times the product of its own factors from\n", + "its current age onward. Dividing by the traditional chainladder ultimates shows the\n", + "drift raising the recent origins most." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "origin-varying-ultimates", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
2261
20011.0000
20021.0010
20031.0040
20041.0090
20051.0180
20061.0290
20071.0430
20081.0660
20091.0950
20101.1350
" + ], + "text/plain": [ + " 2261\n", + "2001 1.000\n", + "2002 1.001\n", + "2003 1.004\n", + "2004 1.009\n", + "2005 1.018\n", + "2006 1.029\n", + "2007 1.043\n", + "2008 1.066\n", + "2009 1.095\n", + "2010 1.135" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plain = cl.Chainladder().fit(cl.Development().fit_transform(genins))\n", + "drift = cl.Chainladder().fit(drifting.transform(genins))\n", + "(drift.ultimate_ / plain.ultimate_).round(3)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "id": "origin-varying-note", + "metadata": {}, + "source": [ + "```{note}\n", + "The `origin:I(development / 12)` term illustrates one kind of time-heterogeneity. Test\n", + "any such term against the data, for example with residuals by origin, before relying\n", + "on it. `TweedieGLM` builds a similar pipeline; this example calls `DevelopmentML`\n", + "directly so that it can set `alpha=0` on the regressor.\n", + "```" + ] + }, { "attachments": {}, "cell_type": "markdown", From cbc3040800368c99f62e086dea5a6b8ce9c888c0 Mon Sep 17 00:00:00 2001 From: Simon Koch-Sultan Date: Wed, 18 Nov 2026 23:02:38 +0000 Subject: [PATCH 2/2] [DOCS] Use TweedieGLM with alpha=0 in the origin-varying example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- docs/user_guide/development.ipynb | 38 +++++++++---------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/docs/user_guide/development.ipynb b/docs/user_guide/development.ipynb index 54c78ef04..21ec044a3 100644 --- a/docs/user_guide/development.ipynb +++ b/docs/user_guide/development.ipynb @@ -7501,30 +7501,12 @@ } ], "source": [ - "from sklearn.linear_model import TweedieRegressor\n", - "\n", "genins = cl.load_sample(\"genins\")\n", "\n", - "\n", - "def odp_glm(formula):\n", - " # Unpenalized ODP GLM on incrementals with a patsy design matrix\n", - " return cl.DevelopmentML(\n", - " Pipeline(\n", - " steps=[\n", - " (\"design_matrix\", cl.PatsyFormula(formula)),\n", - " (\n", - " \"model\",\n", - " TweedieRegressor(\n", - " power=1, link=\"log\", alpha=0, fit_intercept=False, max_iter=1000\n", - " ),\n", - " ),\n", - " ]\n", - " ),\n", - " y_ml=\"values\",\n", - " )\n", - "\n", - "\n", - "cross_classified = odp_glm(\"C(development) + C(origin)\").fit(genins)\n", + "# alpha=0 turns off the default L2 penalty\n", + "cross_classified = cl.TweedieGLM(\n", + " design_matrix=\"C(development) + C(origin)\", alpha=0, max_iter=1000\n", + ").fit(genins)\n", "cross_classified.ldf_.iloc[..., :3].round(3)" ] }, @@ -7642,9 +7624,11 @@ } ], "source": [ - "drifting = odp_glm(\"C(development) + C(origin) + origin:I(development / 12)\").fit(\n", - " genins\n", - ")\n", + "drifting = cl.TweedieGLM(\n", + " design_matrix=\"C(development) + C(origin) + origin:I(development / 12)\",\n", + " alpha=0,\n", + " max_iter=1000,\n", + ").fit(genins)\n", "drifting.ldf_.iloc[..., :3].round(3)" ] }, @@ -7754,8 +7738,8 @@ "```{note}\n", "The `origin:I(development / 12)` term illustrates one kind of time-heterogeneity. Test\n", "any such term against the data, for example with residuals by origin, before relying\n", - "on it. `TweedieGLM` builds a similar pipeline; this example calls `DevelopmentML`\n", - "directly so that it can set `alpha=0` on the regressor.\n", + "on it. `TweedieGLM` applies an L2 penalty by default, so this example sets `alpha=0` to fit\n", + "the unpenalized GLM.\n", "```" ] },