# Beyond the GLM: CAS Monograph 16 with prospicio

CAS Monograph 16 is *From GLMs to Comprehensive Insurance Pricing: Techniques and Challenges* (Alan Chalk, David Deacon, Montserrat Guillen and Max Martinelli, 2025). It starts where the GLM monograph of Goldburd and others stops (the [Goldburd guide](glm-ratemaking-goldburd.md) covers the GLM) and asks what a pricing team does next. This guide covers chapters 3 to 6: measuring a model on unseen data, penalized regression, step and hinge functions, and factors with thousands of levels. The second part, [`glm-to-comprehensive-pricing-chalk-2.md`](glm-to-comprehensive-pricing-chalk-2.md), covers chapters 7 to 10. Table and section numbers are the monograph's.

**What this guide reproduces.** The monograph's case studies use data that is not available offline (the FAA aircraft registry joined to NTSB accident records, UK road accident counts, and a simulated auto portfolio whose rows are not published), so this guide does not recompute their coefficients or plots. It reproduces every worked example whose inputs the monograph prints, each with the monograph's value beside prospicio's. To show the methods on data, it simulates a motor portfolio with a known ground truth, as section 2.3 of the monograph does (section 1.2 builds it with a fixed seed). Models are compared by ranking and by pseudo-R2 rounded to three decimals, because gradient boosting libraries change the later digits between versions.


# 1. Measuring performance (chapter 3)


## 1.1 Pseudo-R2

The monograph scores every model by the share of the possible improvement in log-likelihood that it achieves, from the null model (the mean for everyone) to the saturated model (each record at its own outcome). Deviance is twice the gap to the saturated model, so this share is `1 - D_model / D_null`, the deviance explained. Table 3.1 has four records, two claims and predictions 0.2 to 0.8:


``` python
import math

import pandas as pd
from great_tables import GT
from prospicio.models import deviance

y = [0.0, 0.0, 1.0, 1.0]
mu = [0.2, 0.4, 0.6, 0.8]
null = [sum(y) / len(y)] * len(y)


def loglik(y, mu):
    """Poisson log-likelihood without the log(y!) constant, as in section 3.1."""
    return sum(yi * math.log(mi) - mi for yi, mi in zip(y, mu))


ll_model, ll_null = loglik(y, mu), loglik(y, null)
ll_sat = sum(yi * math.log(yi) - yi for yi in y if yi > 0)
d_model, d_null = deviance("poisson", y, mu), deviance("poisson", y, null)
check = pd.DataFrame({
    "measure": ["log-likelihood, model", "log-likelihood, null", "log-likelihood, saturated",
                "pseudo-R2 from log-likelihoods", "pseudo-R2 from deviances"],
    "prospicio": [ll_model, ll_null, ll_sat, (ll_model - ll_null) / (ll_sat - ll_null),
                  1 - d_model / d_null],
    "book": ["-2.734", "-3.386", "-2", "47%", "47%"],
})
(GT(check, rowname_col="measure")
 .tab_header("Table 3.1: pseudo-R2 of four records", "Poisson log-likelihood without the log(y!) constant")
 .fmt_number("prospicio", decimals=3))
```


<style>
#rqikqpbwyb table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#rqikqpbwyb thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#rqikqpbwyb p { margin: 0; padding: 0; }
 #rqikqpbwyb .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #rqikqpbwyb .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #rqikqpbwyb .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #rqikqpbwyb .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #rqikqpbwyb .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #rqikqpbwyb .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #rqikqpbwyb .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #rqikqpbwyb .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #rqikqpbwyb .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #rqikqpbwyb .gt_column_spanner_outer:first-child { padding-left: 0; }
 #rqikqpbwyb .gt_column_spanner_outer:last-child { padding-right: 0; }
 #rqikqpbwyb .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #rqikqpbwyb .gt_spanner_row { border-bottom-style: hidden; }
 #rqikqpbwyb .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #rqikqpbwyb .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #rqikqpbwyb .gt_from_md> :first-child { margin-top: 0; }
 #rqikqpbwyb .gt_from_md> :last-child { margin-bottom: 0; }
 #rqikqpbwyb .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #rqikqpbwyb .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #rqikqpbwyb .gt_indent_1 { text-indent: 5px; }
 #rqikqpbwyb .gt_indent_2 { text-indent: calc(5px * 2); }
 #rqikqpbwyb .gt_indent_3 { text-indent: calc(5px * 3); }
 #rqikqpbwyb .gt_indent_4 { text-indent: calc(5px * 4); }
 #rqikqpbwyb .gt_indent_5 { text-indent: calc(5px * 5); }
 #rqikqpbwyb .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #rqikqpbwyb .gt_row_group_first td { border-top-width: 2px; }
 #rqikqpbwyb .gt_row_group_first th { border-top-width: 2px; }
 #rqikqpbwyb .gt_striped { color: #333333; background-color: #F4F4F4; }
 #rqikqpbwyb .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #rqikqpbwyb .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #rqikqpbwyb .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #rqikqpbwyb .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #rqikqpbwyb .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #rqikqpbwyb .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #rqikqpbwyb .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #rqikqpbwyb .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #rqikqpbwyb .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #rqikqpbwyb .gt_left { text-align: left; }
 #rqikqpbwyb .gt_center { text-align: center; }
 #rqikqpbwyb .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #rqikqpbwyb .gt_font_normal { font-weight: normal; }
 #rqikqpbwyb .gt_font_bold { font-weight: bold; }
 #rqikqpbwyb .gt_font_italic { font-style: italic; }
 #rqikqpbwyb .gt_super { font-size: 65%; }
 #rqikqpbwyb .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #rqikqpbwyb .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #rqikqpbwyb .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #rqikqpbwyb .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #rqikqpbwyb .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #rqikqpbwyb .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Table 3.1: pseudo-R2 of four records</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Poisson log-likelihood without the log(y!) constant</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="book" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">log-likelihood, model</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">−2.734</td>
<td class="gt_row gt_right" headers="stub-1 book">-2.734</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">log-likelihood, null</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">−3.386</td>
<td class="gt_row gt_right" headers="stub-2 book">-3.386</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">log-likelihood, saturated</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">−2.000</td>
<td class="gt_row gt_right" headers="stub-3 book">-2</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">pseudo-R2 from log-likelihoods</th>
<td class="gt_row gt_right" headers="stub-4 prospicio">0.471</td>
<td class="gt_row gt_right" headers="stub-4 book">47%</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">pseudo-R2 from deviances</th>
<td class="gt_row gt_right" headers="stub-5 prospicio">0.471</td>
<td class="gt_row gt_right" headers="stub-5 book">47%</td>
</tr>
</tbody>
</table>


[deviance](../reference/models.deviance.md#prospicio.models.deviance) also takes prior weights, for the exposure-weighted version of section 3.7.2. It multiplies each record's deviance by its exposure, in the model and null deviance.

Two more checks are arithmetic on printed values (Table 3.6 and the rebasing factor of section 3.7.4):


``` python
(GT(pd.DataFrame({
    "quantity": ["Table 3.6, linear predictor", "Table 3.6, frequency", "Section 3.7.4, rebasing factor"],
    "prospicio": [-2.447 + 0.410 + 5 * -0.086, math.exp(-2.467), 0.004593 / 0.004579],
    "book": ["-2.467", "0.085", "1.0031"],
}), rowname_col="quantity")
 .tab_header("Arithmetic on printed values")
 .fmt_number("prospicio", rows=[0, 1], decimals=3)
 .fmt_number("prospicio", rows=[2], decimals=4))
```


<style>
#qutcgoptbq table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#qutcgoptbq thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#qutcgoptbq p { margin: 0; padding: 0; }
 #qutcgoptbq .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #qutcgoptbq .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #qutcgoptbq .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #qutcgoptbq .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #qutcgoptbq .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #qutcgoptbq .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qutcgoptbq .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #qutcgoptbq .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #qutcgoptbq .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #qutcgoptbq .gt_column_spanner_outer:first-child { padding-left: 0; }
 #qutcgoptbq .gt_column_spanner_outer:last-child { padding-right: 0; }
 #qutcgoptbq .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #qutcgoptbq .gt_spanner_row { border-bottom-style: hidden; }
 #qutcgoptbq .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #qutcgoptbq .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #qutcgoptbq .gt_from_md> :first-child { margin-top: 0; }
 #qutcgoptbq .gt_from_md> :last-child { margin-bottom: 0; }
 #qutcgoptbq .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #qutcgoptbq .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #qutcgoptbq .gt_indent_1 { text-indent: 5px; }
 #qutcgoptbq .gt_indent_2 { text-indent: calc(5px * 2); }
 #qutcgoptbq .gt_indent_3 { text-indent: calc(5px * 3); }
 #qutcgoptbq .gt_indent_4 { text-indent: calc(5px * 4); }
 #qutcgoptbq .gt_indent_5 { text-indent: calc(5px * 5); }
 #qutcgoptbq .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #qutcgoptbq .gt_row_group_first td { border-top-width: 2px; }
 #qutcgoptbq .gt_row_group_first th { border-top-width: 2px; }
 #qutcgoptbq .gt_striped { color: #333333; background-color: #F4F4F4; }
 #qutcgoptbq .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qutcgoptbq .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #qutcgoptbq .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #qutcgoptbq .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qutcgoptbq .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #qutcgoptbq .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #qutcgoptbq .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #qutcgoptbq .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qutcgoptbq .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #qutcgoptbq .gt_left { text-align: left; }
 #qutcgoptbq .gt_center { text-align: center; }
 #qutcgoptbq .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #qutcgoptbq .gt_font_normal { font-weight: normal; }
 #qutcgoptbq .gt_font_bold { font-weight: bold; }
 #qutcgoptbq .gt_font_italic { font-style: italic; }
 #qutcgoptbq .gt_super { font-size: 65%; }
 #qutcgoptbq .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qutcgoptbq .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #qutcgoptbq .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qutcgoptbq .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #qutcgoptbq .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #qutcgoptbq .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Arithmetic on printed values</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="book" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">Table 3.6, linear predictor</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">−2.467</td>
<td class="gt_row gt_right" headers="stub-1 book">-2.467</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">Table 3.6, frequency</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">0.085</td>
<td class="gt_row gt_right" headers="stub-2 book">0.085</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">Section 3.7.4, rebasing factor</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">1.0031</td>
<td class="gt_row gt_right" headers="stub-3 book">1.0031</td>
</tr>
</tbody>
</table>


## 1.2 A portfolio with a known truth, and folds from the policy number

The simulated portfolio takes the place of the monograph's case studies: 20,000 policies with driver age, vehicle age, region, power, a 300-level make, a noise feature and a young-driver, high-power interaction. The true log frequency has a steep young-driver effect and a rise after age 60, a vehicle-age effect that falls until age 6 and is flat after, region and power effects, a make effect for each of 300 makes (make sizes fall like a Zipf law) and an extra load for young drivers of high-power cars.

`noise` has no effect. `exper` (years since the driving test) is highly correlated with age and has no effect of its own.

Section 3.7.3 recommends folds from the policy number, so that anyone can rebuild them and all records of one policy fall in one fold. Here the fold is the last digit of the row number. Folds 7 to 9 (30%) are the test data; folds 0 to 6 are the seven cross-validation folds.


``` python
import numpy as np

rng = np.random.default_rng(2025)
n = 20_000
age = rng.integers(18, 81, n)
veh_age = rng.integers(0, 21, n)
power = rng.choice(["low", "mid", "high"], n, p=[0.5, 0.35, 0.15])
region = rng.choice(list("ABCDEF"), n, p=[0.3, 0.2, 0.15, 0.15, 0.1, 0.1])
zipf = 1 / np.arange(1, 301) ** 1.1
make = rng.choice(300, n, p=zipf / zipf.sum())
make_effect = rng.normal(0, 0.4, 300)
noise = rng.normal(size=n)
exper = np.maximum(age - 17 - rng.poisson(2, n), 0)
exposure = rng.uniform(0.5, 1.0, n).round(3)
true_lp = (
    np.log(0.25)
    + 0.9 * np.exp(-(age - 18) / 6)
    + 0.0015 * np.maximum(age - 60, 0) ** 1.5
    - 0.08 * np.minimum(veh_age, 6)
    + np.select([region == "B", region == "C", region == "F"], [0.15, -0.2, 0.3], 0.0)
    + make_effect[make]
    + np.where(power == "high", 0.25, 0.0)
    + np.where((power == "high") & (age < 25), 0.6, 0.0)
)
claims = rng.poisson(np.exp(true_lp) * exposure).astype(float)
fold = np.arange(n) % 10
train = fold < 7
print(f"{n} policies, {exposure.sum():.0f} car-years, {claims.sum():.0f} claims")
print(f"frequency {claims.sum() / exposure.sum():.4f}; makes with under 20 policies: "
      f"{(np.bincount(make, minlength=300) < 20).sum()}")
print(f"correlation of age and exper {np.corrcoef(age, exper)[0, 1]:.3f}")
```


    20000 policies, 15000 car-years, 3659 claims
    frequency 0.2439; makes with under 20 policies: 166
    correlation of age and exper 0.997


The null model is the mean frequency times each record's exposure. `cv_score` trains on six of the seven folds, scores the seventh and averages, for any function that fits and predicts (a GLM, a GAM or a boosting model).


``` python
from prospicio.models import Design


def pseudo_r2(y, mu, expo):
    y, mu, expo = (np.asarray(v, float) for v in (y, mu, expo))
    null = expo * y.sum() / expo.sum()
    return 1 - deviance("poisson", y.tolist(), mu.tolist()) / deviance("poisson", y.tolist(), null.tolist())


def rows(mask):
    return np.flatnonzero(mask).tolist()


def cv_score(fit_predict, X, folds=range(7)):
    scores = []
    for k in folds:
        fit_rows, val = rows(train & (fold != k)), rows(fold == k)
        mu = fit_predict(X.select(fit_rows), claims[fit_rows].tolist(), X.select(val))
        scores.append(pseudo_r2(claims[val], mu, exposure[val]))
    return float(np.mean(scores)), scores


def columns(*cols):
    return [np.asarray(c, float).tolist() for c in cols]


ones = np.ones(n)
log_expo = np.log(exposure).tolist()
region_d = [(region == r).astype(float) for r in "BCDEF"]
power_d = [(power == p).astype(float) for p in ["mid", "high"]]
factor_names = [f"region[{r}]" for r in "BCDEF"] + ["power[mid]", "power[high]"]
truth = np.exp(true_lp) * exposure
print(f"pseudo-R2 of the true frequencies on the test data {pseudo_r2(claims[~train], truth[~train], exposure[~train]):.3f}")
```


    pseudo-R2 of the true frequencies on the test data 0.089


A perfect model explains only a few percent of the deviance of individual claim counts, because most of each count is chance (section 3.7.1; the monograph's perfect model scored 0.051), so compare models on the same data.


## 1.3 Null, baseline and benchmark models

The null model predicts the training mean. Its validation pseudo-R2 is slightly negative, not zero, because the training mean is not the validation fold's mean (Table 3.3). Rebasing to the fold's mean (section 3.7.4) makes it exactly zero.

The baseline is a Poisson GLM with age and vehicle age as straight lines and region and power as factors (section 3.5). The benchmark is LightGBM through [prospicio.boosting.Booster](../reference/boosting.Booster.md#prospicio.boosting.Booster) (section 3.6), with the make as a plain number so the trees can split on it.


``` python
from prospicio.boosting import Booster
from prospicio.models import Glm

X_null = Design(columns(ones), ["(Intercept)"], offset=log_expo)
X_base = Design(columns(ones, age, veh_age, *region_d, *power_d),
                ["(Intercept)", "age", "veh_age", *factor_names], offset=log_expo)
X_tree = Design(columns(age, veh_age, np.unique(region, return_inverse=True)[1],
                        np.unique(power, return_inverse=True)[1], make, noise),
                ["age", "veh_age", "region", "power", "make", "noise"], offset=log_expo)


def glm(d, y, new):
    return Glm("poisson").fit(d, y).predict(new)


def gbm(d, y, new, rounds=150):
    params = {"num_leaves": 7, "min_data_in_leaf": 200, "num_threads": 1}
    return Booster("poisson", n_rounds=rounds, learning_rate=0.05, params=params, seed=1).fit(d, y).predict(new)


null_cv, null_folds = cv_score(glm, X_null)
print("null model by fold     ", [f"{s:.4f}" for s in null_folds])
fit_rows, val = rows(train & (fold != 0)), rows(fold == 0)
mu0 = np.asarray(glm(X_null.select(fit_rows), claims[fit_rows].tolist(), X_null.select(val)))
rebased = mu0 * claims[val].sum() / mu0.sum()
print(f"fold 0 rebased          {abs(pseudo_r2(claims[val], rebased, exposure[val])):.4f}")
print(f"baseline GLM  cv        {cv_score(glm, X_base)[0]:.3f}")
print(f"benchmark GBM cv        {cv_score(gbm, X_tree)[0]:.3f}")
```


    null model by fold      ['-0.0000', '-0.0000', '-0.0031', '-0.0000', '-0.0009', '-0.0012', '-0.0028']
    fold 0 rebased          0.0000
    baseline GLM  cv        0.021
    benchmark GBM cv        0.045


The order is the monograph's: null, GLM, boosting model well above the GLM. The rest of the monograph closes that gap with models that a pricing team can explain.


# 2. Penalized regression (chapter 4)


## 2.1 Why fewer parameters can predict better

In the rare-car example of section 4.1, ten insurers each see one of ten cars for a year, and one car has a claim. An unpenalized GLM at each insurer predicts 100% or 0%: right on average (10%), far off each time. The spread of the ten predictions is the variance of the model.


``` python
preds = np.array([1.0] + [0.0] * 9)
print(f"mean {preds.mean():.2f}, variance {preds.var():.2f}, sd {preds.std():.2f} (printed 0.09, 0.30)")
```


    mean 0.10, variance 0.09, sd 0.30 (printed 0.09, 0.30)


A model that ignores this car and predicts the 5% average for every make has bias but no variance, and every insurer is closer to the truth with it. Penalized regression trades bias for variance continuously, by maximizing the log-likelihood less a penalty on the coefficients:

- ridge: the sum of their squares,
- lasso: the sum of their absolute values,
- elastic net: a mix of the two, with weight [alpha](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.alpha) on the lasso part.

prospicio's [ElasticNet](../reference/models.ElasticNet.md#prospicio.models.ElasticNet) minimizes the glmnet objective: half the mean deviance plus [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) times the penalty. The intercept is not penalized and the columns are standardized first. Its [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) and [alpha](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.alpha) are the monograph's lambda and alpha (section 4.6.3).


## 2.2 Ridge in closed form, and why features are standardized

For one feature, a normal response and no intercept, ridge divides the mean of `x * y` by the mean of `x**2` plus [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) (section 4.7.1), which pulls the least squares estimate towards zero. In section 4.7.2 the means are 10 and 5 with length in metres, and [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) = 5. In centimetres they are 100 and 10,000 times larger, so the same [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) shrinks almost nothing:


``` python
units = []
for unit, xy, xx, scale in [("metres", 10.0, 5.0, 1.0), ("centimetres", 1_000.0, 50_000.0, 100.0)]:
    ols, ridge_b = xy / xx, xy / (xx + 5.0)
    units.append({"unit": unit, "least squares": ols, "ridge": ridge_b, "frequency at 1 m": ridge_b * scale})
(GT(pd.DataFrame(units), rowname_col="unit")
 .tab_header("Section 4.7.2: ridge on one length in two units", "lam = 5")
 .fmt_number("least squares", decimals=4)
 .fmt_number("ridge", decimals=6)
 .fmt_number("frequency at 1 m", decimals=4))
```


<style>
#lihpsrxser table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#lihpsrxser thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#lihpsrxser p { margin: 0; padding: 0; }
 #lihpsrxser .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #lihpsrxser .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #lihpsrxser .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #lihpsrxser .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #lihpsrxser .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #lihpsrxser .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lihpsrxser .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #lihpsrxser .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #lihpsrxser .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #lihpsrxser .gt_column_spanner_outer:first-child { padding-left: 0; }
 #lihpsrxser .gt_column_spanner_outer:last-child { padding-right: 0; }
 #lihpsrxser .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #lihpsrxser .gt_spanner_row { border-bottom-style: hidden; }
 #lihpsrxser .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #lihpsrxser .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #lihpsrxser .gt_from_md> :first-child { margin-top: 0; }
 #lihpsrxser .gt_from_md> :last-child { margin-bottom: 0; }
 #lihpsrxser .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #lihpsrxser .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #lihpsrxser .gt_indent_1 { text-indent: 5px; }
 #lihpsrxser .gt_indent_2 { text-indent: calc(5px * 2); }
 #lihpsrxser .gt_indent_3 { text-indent: calc(5px * 3); }
 #lihpsrxser .gt_indent_4 { text-indent: calc(5px * 4); }
 #lihpsrxser .gt_indent_5 { text-indent: calc(5px * 5); }
 #lihpsrxser .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #lihpsrxser .gt_row_group_first td { border-top-width: 2px; }
 #lihpsrxser .gt_row_group_first th { border-top-width: 2px; }
 #lihpsrxser .gt_striped { color: #333333; background-color: #F4F4F4; }
 #lihpsrxser .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lihpsrxser .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #lihpsrxser .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #lihpsrxser .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lihpsrxser .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #lihpsrxser .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #lihpsrxser .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #lihpsrxser .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lihpsrxser .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #lihpsrxser .gt_left { text-align: left; }
 #lihpsrxser .gt_center { text-align: center; }
 #lihpsrxser .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #lihpsrxser .gt_font_normal { font-weight: normal; }
 #lihpsrxser .gt_font_bold { font-weight: bold; }
 #lihpsrxser .gt_font_italic { font-style: italic; }
 #lihpsrxser .gt_super { font-size: 65%; }
 #lihpsrxser .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lihpsrxser .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #lihpsrxser .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lihpsrxser .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #lihpsrxser .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #lihpsrxser .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">Section 4.7.2: ridge on one length in two units</th>
</tr>
<tr class="gt_heading">
<th colspan="4" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">lam = 5</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="least-squares" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">least squares</th>
<th id="ridge" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">ridge</th>
<th id="frequency-at-1-m" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">frequency at 1 m</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">metres</th>
<td class="gt_row gt_right" headers="stub-1 least-squares">2.0000</td>
<td class="gt_row gt_right" headers="stub-1 ridge">1.000000</td>
<td class="gt_row gt_right" headers="stub-1 frequency-at-1-m">1.0000</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">centimetres</th>
<td class="gt_row gt_right" headers="stub-2 least-squares">0.0200</td>
<td class="gt_row gt_right" headers="stub-2 ridge">0.019998</td>
<td class="gt_row gt_right" headers="stub-2 frequency-at-1-m">1.9998</td>
</tr>
</tbody>
</table>


The monograph prints 0.019 and 1.9 for centimetres: it truncated the exact values. The units, not the data, set the effect of the penalty.

Standardizing each feature to unit standard deviation before the penalty removes this. [ElasticNet](../reference/models.ElasticNet.md#prospicio.models.ElasticNet) does it by default and returns coefficients on the original scale, so ridge on metres and on centimetres differ by exactly the factor of 100:


``` python
from prospicio.models import ElasticNet

x_m = rng.uniform(1.0, 5.0, 200)
y_len = 2.0 * x_m + rng.normal(0, 1, 200)
ridge = ElasticNet("gaussian", alpha=0.0, lam=0.5)
b_m = ridge.fit(Design(columns(np.ones(200), x_m), ["(Intercept)", "x"]), y_len.tolist()).coefficients[1]
b_cm = ridge.fit(Design(columns(np.ones(200), 100 * x_m), ["(Intercept)", "x"]), y_len.tolist()).coefficients[1]
print(f"metres {b_m:.6f}, centimetres x 100 {100 * b_cm:.6f}")
```


    metres 1.343762, centimetres x 100 1.343762


## 2.3 The lasso sets coefficients to exactly zero

Section 4.7.3: for one standardized feature, the lasso estimate is the least squares estimate moved towards zero by [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam), and exactly zero beyond it (soft-thresholding). With this objective the least squares estimate is the mean of `x * y`:


``` python
x_std = rng.normal(size=500)
x_std = (x_std - x_std.mean()) / x_std.std()
y_soft = 0.3 * x_std + rng.normal(0, 1, 500)
y_soft -= y_soft.mean()
ols = float(np.mean(x_std * y_soft))
X_soft = Design(columns(np.ones(500), x_std), ["(Intercept)", "x"])
soft = []
for lam in [0.0, 0.1, 0.2, 0.4]:
    b = ElasticNet("gaussian", alpha=1.0, lam=lam).fit(X_soft, y_soft.tolist()).coefficients[1]
    soft.append({"lam": f"{lam:.1f}", "lasso": b, "soft threshold": np.sign(ols) * max(abs(ols) - lam, 0.0)})
(GT(pd.DataFrame(soft), rowname_col="lam")
 .tab_header("Section 4.7.3: the lasso is the soft threshold", "One standardized feature")
 .fmt_number(["lasso", "soft threshold"], decimals=4))
```


<style>
#meyiaptrgm table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#meyiaptrgm thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#meyiaptrgm p { margin: 0; padding: 0; }
 #meyiaptrgm .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #meyiaptrgm .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #meyiaptrgm .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #meyiaptrgm .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #meyiaptrgm .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #meyiaptrgm .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #meyiaptrgm .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #meyiaptrgm .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #meyiaptrgm .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #meyiaptrgm .gt_column_spanner_outer:first-child { padding-left: 0; }
 #meyiaptrgm .gt_column_spanner_outer:last-child { padding-right: 0; }
 #meyiaptrgm .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #meyiaptrgm .gt_spanner_row { border-bottom-style: hidden; }
 #meyiaptrgm .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #meyiaptrgm .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #meyiaptrgm .gt_from_md> :first-child { margin-top: 0; }
 #meyiaptrgm .gt_from_md> :last-child { margin-bottom: 0; }
 #meyiaptrgm .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #meyiaptrgm .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #meyiaptrgm .gt_indent_1 { text-indent: 5px; }
 #meyiaptrgm .gt_indent_2 { text-indent: calc(5px * 2); }
 #meyiaptrgm .gt_indent_3 { text-indent: calc(5px * 3); }
 #meyiaptrgm .gt_indent_4 { text-indent: calc(5px * 4); }
 #meyiaptrgm .gt_indent_5 { text-indent: calc(5px * 5); }
 #meyiaptrgm .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #meyiaptrgm .gt_row_group_first td { border-top-width: 2px; }
 #meyiaptrgm .gt_row_group_first th { border-top-width: 2px; }
 #meyiaptrgm .gt_striped { color: #333333; background-color: #F4F4F4; }
 #meyiaptrgm .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #meyiaptrgm .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #meyiaptrgm .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #meyiaptrgm .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #meyiaptrgm .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #meyiaptrgm .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #meyiaptrgm .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #meyiaptrgm .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #meyiaptrgm .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #meyiaptrgm .gt_left { text-align: left; }
 #meyiaptrgm .gt_center { text-align: center; }
 #meyiaptrgm .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #meyiaptrgm .gt_font_normal { font-weight: normal; }
 #meyiaptrgm .gt_font_bold { font-weight: bold; }
 #meyiaptrgm .gt_font_italic { font-style: italic; }
 #meyiaptrgm .gt_super { font-size: 65%; }
 #meyiaptrgm .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #meyiaptrgm .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #meyiaptrgm .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #meyiaptrgm .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #meyiaptrgm .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #meyiaptrgm .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Section 4.7.3: the lasso is the soft threshold</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">One standardized feature</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="lasso" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">lasso</th>
<th id="soft-threshold" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">soft threshold</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">0.0</th>
<td class="gt_row gt_right" headers="stub-1 lasso">0.3382</td>
<td class="gt_row gt_right" headers="stub-1 soft-threshold">0.3382</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">0.1</th>
<td class="gt_row gt_right" headers="stub-2 lasso">0.2382</td>
<td class="gt_row gt_right" headers="stub-2 soft-threshold">0.2382</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">0.2</th>
<td class="gt_row gt_right" headers="stub-3 lasso">0.1382</td>
<td class="gt_row gt_right" headers="stub-3 soft-threshold">0.1382</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">0.4</th>
<td class="gt_row gt_right" headers="stub-4 lasso">0.0000</td>
<td class="gt_row gt_right" headers="stub-4 soft-threshold">0.0000</td>
</tr>
</tbody>
</table>


## 2.4 Paths and choosing the penalty by cross-validation

Tables 4.1 and 4.2 show the coefficient of log aircraft age shrinking as the penalty grows: smoothly for ridge, to zero for the lasso. The block repeats this with log driver age. For a Poisson model, records with equal features can be summed (section 8.3), so the age-only models use 63 ages times 10 folds:


``` python
key = age * 10 + fold
cells, cell = np.unique(key, return_inverse=True)
cell_claims = np.bincount(cell, claims)
cell_expo = np.bincount(cell, exposure)
cell_age, cell_fold = cells // 10, cells % 10
cell_off = np.log(cell_expo).tolist()
tr_cells = rows(cell_fold < 7)
X_logage = Design(columns(np.ones(len(cells)), np.log(cell_age)), ["(Intercept)", "log_age"], offset=cell_off)
Xa, ya = X_logage.select(tr_cells), cell_claims[tr_cells].tolist()
paths = {}
for name, a in [("ridge", 0.0), ("lasso", 1.0)]:
    net = ElasticNet("poisson", alpha=a)
    top = ElasticNet("poisson", alpha=1.0).lambda_max(Xa, ya)
    scale = 100.0 if a == 0.0 else 1.0
    path = net.path(Xa, ya, [scale * top * f for f in [1.0, 0.3, 0.1, 0.03, 0.01, 0.0]])
    paths[name] = [fit.coefficients[1] for fit in path]
(GT(pd.DataFrame({"penalty": ["1", "0.3", "0.1", "0.03", "0.01", "0 (GLM)"], **paths}), rowname_col="penalty")
 .tab_header("Tables 4.1 and 4.2: the log-age coefficient along the path",
             "Penalty as a share of the largest one; ridge starts at 100 times the lasso's")
 .fmt_number(["ridge", "lasso"], decimals=3))
```


<style>
#lkkkiiieqr table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#lkkkiiieqr thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#lkkkiiieqr p { margin: 0; padding: 0; }
 #lkkkiiieqr .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #lkkkiiieqr .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #lkkkiiieqr .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #lkkkiiieqr .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #lkkkiiieqr .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #lkkkiiieqr .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lkkkiiieqr .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #lkkkiiieqr .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #lkkkiiieqr .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #lkkkiiieqr .gt_column_spanner_outer:first-child { padding-left: 0; }
 #lkkkiiieqr .gt_column_spanner_outer:last-child { padding-right: 0; }
 #lkkkiiieqr .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #lkkkiiieqr .gt_spanner_row { border-bottom-style: hidden; }
 #lkkkiiieqr .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #lkkkiiieqr .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #lkkkiiieqr .gt_from_md> :first-child { margin-top: 0; }
 #lkkkiiieqr .gt_from_md> :last-child { margin-bottom: 0; }
 #lkkkiiieqr .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #lkkkiiieqr .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #lkkkiiieqr .gt_indent_1 { text-indent: 5px; }
 #lkkkiiieqr .gt_indent_2 { text-indent: calc(5px * 2); }
 #lkkkiiieqr .gt_indent_3 { text-indent: calc(5px * 3); }
 #lkkkiiieqr .gt_indent_4 { text-indent: calc(5px * 4); }
 #lkkkiiieqr .gt_indent_5 { text-indent: calc(5px * 5); }
 #lkkkiiieqr .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #lkkkiiieqr .gt_row_group_first td { border-top-width: 2px; }
 #lkkkiiieqr .gt_row_group_first th { border-top-width: 2px; }
 #lkkkiiieqr .gt_striped { color: #333333; background-color: #F4F4F4; }
 #lkkkiiieqr .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lkkkiiieqr .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #lkkkiiieqr .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #lkkkiiieqr .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #lkkkiiieqr .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #lkkkiiieqr .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #lkkkiiieqr .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #lkkkiiieqr .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lkkkiiieqr .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #lkkkiiieqr .gt_left { text-align: left; }
 #lkkkiiieqr .gt_center { text-align: center; }
 #lkkkiiieqr .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #lkkkiiieqr .gt_font_normal { font-weight: normal; }
 #lkkkiiieqr .gt_font_bold { font-weight: bold; }
 #lkkkiiieqr .gt_font_italic { font-style: italic; }
 #lkkkiiieqr .gt_super { font-size: 65%; }
 #lkkkiiieqr .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lkkkiiieqr .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #lkkkiiieqr .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #lkkkiiieqr .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #lkkkiiieqr .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #lkkkiiieqr .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Tables 4.1 and 4.2: the log-age coefficient along the path</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Penalty as a share of the largest one; ridge starts at 100 times the lasso's</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="ridge" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">ridge</th>
<th id="lasso" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">lasso</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">1</th>
<td class="gt_row gt_right" headers="stub-1 ridge">−0.023</td>
<td class="gt_row gt_right" headers="stub-1 lasso">0.000</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">0.3</th>
<td class="gt_row gt_right" headers="stub-2 ridge">−0.067</td>
<td class="gt_row gt_right" headers="stub-2 lasso">−0.292</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">0.1</th>
<td class="gt_row gt_right" headers="stub-3 ridge">−0.153</td>
<td class="gt_row gt_right" headers="stub-3 lasso">−0.373</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">0.03</th>
<td class="gt_row gt_right" headers="stub-4 ridge">−0.275</td>
<td class="gt_row gt_right" headers="stub-4 lasso">−0.401</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">0.01</th>
<td class="gt_row gt_right" headers="stub-5 ridge">−0.354</td>
<td class="gt_row gt_right" headers="stub-5 lasso">−0.409</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">0 (GLM)</th>
<td class="gt_row gt_right" headers="stub-6 ridge">−0.413</td>
<td class="gt_row gt_right" headers="stub-6 lasso">−0.413</td>
</tr>
</tbody>
</table>


Section 4.3 chooses [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) by fitting the path on six folds and scoring the seventh. [ElasticNet.cross_validate](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.cross_validate) does this on the policy-number folds. It returns the [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) with the best mean validation deviance and, for the one-standard-error rule of section 4.6.5, the largest [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) within one standard error of it:


``` python
def cell_splits(cell_rows, cell_folds):
    pos = {r: i for i, r in enumerate(cell_rows)}
    return [([pos[r] for r in cell_rows if cell_folds[r] != k],
             [pos[r] for r in cell_rows if cell_folds[r] == k]) for k in range(7)]


splits = cell_splits(tr_cells, cell_fold)
lasso = ElasticNet("poisson", alpha=0.99)
lams = lasso.lambda_path(Xa, ya, n=30, min_ratio=1e-3)
path_cv = lasso.cross_validate(Xa, ya, lams, splits)
print(f"lam_min at position {lams.index(path_cv.lam_min)} of 30, lam_1se at position {lams.index(path_cv.lam_1se)}")
```


    lam_min at position 29 of 30, lam_1se at position 3


## 2.5 The relaxed lasso

The relaxed lasso (section 4.5) separates selection from shrinkage: it refits the features that the lasso selected with less penalty or none. In prospicio that is a [Glm](../reference/models.Glm.md#prospicio.models.Glm) on the selected columns (section 3.2).


# 3. Nonlinear effects (chapter 5)


## 3.1 Step and hinge functions, from the printed coefficients

A step function is 1 at or above a threshold and 0 below it. A hinge is `max(0, x - knot)`. A single step at age 30 gives `log frequency = -5.2815 - 1.4689 x step_30` (section 5.2). With steps at 5, 15 and 30 the monograph prints four frequencies:


``` python
steps = pd.DataFrame({
    "quantity": ["one step, frequency", "one step, relativity", "three steps, band 1", "three steps, band 2",
                 "three steps, band 3", "three steps, band 4"],
    "prospicio": [math.exp(-5.2815), math.exp(-1.4689),
                  *[math.exp(sum([-4.8292, -0.6881, -0.5711, -0.6237][: i + 1])) for i in range(4)]],
    "book": [0.00509, 0.2302, 0.00783, 0.00394, 0.00222, 0.00119],
})
steps["book / prospicio"] = steps["book"] / steps["prospicio"]
(GT(steps, rowname_col="quantity")
 .tab_header("Section 5.2: frequencies from the printed coefficients", "Bands are cut at ages 5, 15 and 30")
 .fmt_number(["prospicio", "book"], rows=[0, 2, 3, 4, 5], decimals=5)
 .fmt_number(["prospicio", "book"], rows=[1], decimals=4)
 .fmt_number("book / prospicio", decimals=3))
```


<style>
#qsuroimxza table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#qsuroimxza thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#qsuroimxza p { margin: 0; padding: 0; }
 #qsuroimxza .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #qsuroimxza .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #qsuroimxza .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #qsuroimxza .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #qsuroimxza .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #qsuroimxza .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qsuroimxza .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #qsuroimxza .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #qsuroimxza .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #qsuroimxza .gt_column_spanner_outer:first-child { padding-left: 0; }
 #qsuroimxza .gt_column_spanner_outer:last-child { padding-right: 0; }
 #qsuroimxza .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #qsuroimxza .gt_spanner_row { border-bottom-style: hidden; }
 #qsuroimxza .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #qsuroimxza .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #qsuroimxza .gt_from_md> :first-child { margin-top: 0; }
 #qsuroimxza .gt_from_md> :last-child { margin-bottom: 0; }
 #qsuroimxza .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #qsuroimxza .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #qsuroimxza .gt_indent_1 { text-indent: 5px; }
 #qsuroimxza .gt_indent_2 { text-indent: calc(5px * 2); }
 #qsuroimxza .gt_indent_3 { text-indent: calc(5px * 3); }
 #qsuroimxza .gt_indent_4 { text-indent: calc(5px * 4); }
 #qsuroimxza .gt_indent_5 { text-indent: calc(5px * 5); }
 #qsuroimxza .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #qsuroimxza .gt_row_group_first td { border-top-width: 2px; }
 #qsuroimxza .gt_row_group_first th { border-top-width: 2px; }
 #qsuroimxza .gt_striped { color: #333333; background-color: #F4F4F4; }
 #qsuroimxza .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qsuroimxza .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #qsuroimxza .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #qsuroimxza .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #qsuroimxza .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #qsuroimxza .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #qsuroimxza .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #qsuroimxza .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qsuroimxza .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #qsuroimxza .gt_left { text-align: left; }
 #qsuroimxza .gt_center { text-align: center; }
 #qsuroimxza .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #qsuroimxza .gt_font_normal { font-weight: normal; }
 #qsuroimxza .gt_font_bold { font-weight: bold; }
 #qsuroimxza .gt_font_italic { font-style: italic; }
 #qsuroimxza .gt_super { font-size: 65%; }
 #qsuroimxza .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qsuroimxza .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #qsuroimxza .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #qsuroimxza .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #qsuroimxza .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #qsuroimxza .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">Section 5.2: frequencies from the printed coefficients</th>
</tr>
<tr class="gt_heading">
<th colspan="4" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Bands are cut at ages 5, 15 and 30</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="book" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book</th>
<th id="book-prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book / prospicio</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">one step, frequency</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">0.00508</td>
<td class="gt_row gt_right" headers="stub-1 book">0.00509</td>
<td class="gt_row gt_right" headers="stub-1 book-prospicio">1.001</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">one step, relativity</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">0.2302</td>
<td class="gt_row gt_right" headers="stub-2 book">0.2302</td>
<td class="gt_row gt_right" headers="stub-2 book-prospicio">1.000</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">three steps, band 1</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">0.00799</td>
<td class="gt_row gt_right" headers="stub-3 book">0.00783</td>
<td class="gt_row gt_right" headers="stub-3 book-prospicio">0.980</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">three steps, band 2</th>
<td class="gt_row gt_right" headers="stub-4 prospicio">0.00402</td>
<td class="gt_row gt_right" headers="stub-4 book">0.00394</td>
<td class="gt_row gt_right" headers="stub-4 book-prospicio">0.981</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">three steps, band 3</th>
<td class="gt_row gt_right" headers="stub-5 prospicio">0.00227</td>
<td class="gt_row gt_right" headers="stub-5 book">0.00222</td>
<td class="gt_row gt_right" headers="stub-5 book-prospicio">0.978</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">three steps, band 4</th>
<td class="gt_row gt_right" headers="stub-6 prospicio">0.00122</td>
<td class="gt_row gt_right" headers="stub-6 book">0.00119</td>
<td class="gt_row gt_right" headers="stub-6 book-prospicio">0.979</td>
</tr>
</tbody>
</table>


The single step's base frequency differs in the last digit: exp(-5.2815) is 0.005082 (an intercept of -5.2809 or more gives the printed 0.00509).

The three-step frequencies are all about 2% below the printed ones, by almost the same factor in every band, which points at the intercept: -4.85, not -4.8292, gives the printed values and keeps the ratios between bands. Without the data we cannot say which printed number is wrong.

Table 5.7 codes an ordinal feature (pilot quality, five levels) as five cumulative steps. A level's relativity is the exponential of the running sum of the coefficients:


``` python
coef = [0, 0.515, 0, 0.211, 0.206]
(GT(pd.DataFrame({
    "level": ["1", "2", "3", "4", "5"],
    "coefficient": coef,
    "prospicio": [math.exp(sum(coef[: i + 1])) for i in range(5)],
    "book": ["1", "1.673", "1.673", "2.06", "2.539"],
}), rowname_col="level")
 .tab_header("Table 5.7: cumulative relativities of pilot quality")
 .fmt_number(["coefficient", "prospicio"], decimals=3))
```


<style>
#zwkxbtxyue table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#zwkxbtxyue thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#zwkxbtxyue p { margin: 0; padding: 0; }
 #zwkxbtxyue .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #zwkxbtxyue .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #zwkxbtxyue .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #zwkxbtxyue .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #zwkxbtxyue .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #zwkxbtxyue .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #zwkxbtxyue .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #zwkxbtxyue .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #zwkxbtxyue .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #zwkxbtxyue .gt_column_spanner_outer:first-child { padding-left: 0; }
 #zwkxbtxyue .gt_column_spanner_outer:last-child { padding-right: 0; }
 #zwkxbtxyue .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #zwkxbtxyue .gt_spanner_row { border-bottom-style: hidden; }
 #zwkxbtxyue .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #zwkxbtxyue .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #zwkxbtxyue .gt_from_md> :first-child { margin-top: 0; }
 #zwkxbtxyue .gt_from_md> :last-child { margin-bottom: 0; }
 #zwkxbtxyue .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #zwkxbtxyue .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #zwkxbtxyue .gt_indent_1 { text-indent: 5px; }
 #zwkxbtxyue .gt_indent_2 { text-indent: calc(5px * 2); }
 #zwkxbtxyue .gt_indent_3 { text-indent: calc(5px * 3); }
 #zwkxbtxyue .gt_indent_4 { text-indent: calc(5px * 4); }
 #zwkxbtxyue .gt_indent_5 { text-indent: calc(5px * 5); }
 #zwkxbtxyue .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #zwkxbtxyue .gt_row_group_first td { border-top-width: 2px; }
 #zwkxbtxyue .gt_row_group_first th { border-top-width: 2px; }
 #zwkxbtxyue .gt_striped { color: #333333; background-color: #F4F4F4; }
 #zwkxbtxyue .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #zwkxbtxyue .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #zwkxbtxyue .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #zwkxbtxyue .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #zwkxbtxyue .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #zwkxbtxyue .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #zwkxbtxyue .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #zwkxbtxyue .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #zwkxbtxyue .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #zwkxbtxyue .gt_left { text-align: left; }
 #zwkxbtxyue .gt_center { text-align: center; }
 #zwkxbtxyue .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #zwkxbtxyue .gt_font_normal { font-weight: normal; }
 #zwkxbtxyue .gt_font_bold { font-weight: bold; }
 #zwkxbtxyue .gt_font_italic { font-style: italic; }
 #zwkxbtxyue .gt_super { font-size: 65%; }
 #zwkxbtxyue .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #zwkxbtxyue .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #zwkxbtxyue .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #zwkxbtxyue .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #zwkxbtxyue .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #zwkxbtxyue .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="4" id="title" class="gt_heading gt_title gt_font_normal">Table 5.7: cumulative relativities of pilot quality</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="coefficient" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">coefficient</th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="book" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">1</th>
<td class="gt_row gt_right" headers="stub-1 coefficient">0.000</td>
<td class="gt_row gt_right" headers="stub-1 prospicio">1.000</td>
<td class="gt_row gt_right" headers="stub-1 book">1</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">2</th>
<td class="gt_row gt_right" headers="stub-2 coefficient">0.515</td>
<td class="gt_row gt_right" headers="stub-2 prospicio">1.674</td>
<td class="gt_row gt_right" headers="stub-2 book">1.673</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">3</th>
<td class="gt_row gt_right" headers="stub-3 coefficient">0.000</td>
<td class="gt_row gt_right" headers="stub-3 prospicio">1.674</td>
<td class="gt_row gt_right" headers="stub-3 book">1.673</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">4</th>
<td class="gt_row gt_right" headers="stub-4 coefficient">0.211</td>
<td class="gt_row gt_right" headers="stub-4 prospicio">2.067</td>
<td class="gt_row gt_right" headers="stub-4 book">2.06</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">5</th>
<td class="gt_row gt_right" headers="stub-5 coefficient">0.206</td>
<td class="gt_row gt_right" headers="stub-5 prospicio">2.540</td>
<td class="gt_row gt_right" headers="stub-5 book">2.539</td>
</tr>
</tbody>
</table>


The exact fourth value is 2.067: Table 5.7 truncates it and Table 5.8 rounds it to 2.07.


## 3.2 Many steps or hinges, and the lasso picks

Section 5.2 gives the lasso one step at each age and lets cross-validation decide how many stay (section 5.6 uses 25 equally spaced steps). Here the steps are every three years from 20 to 77, on the aggregated ages:


``` python
knots = list(range(20, 80, 3))
step_names = ["(Intercept)"] + [f"age_stp_{a}" for a in knots]
X_steps = Design(columns(np.ones(len(cells)), *[cell_age >= a for a in knots]), step_names, offset=cell_off)
Xt, yt = X_steps.select(tr_cells), cell_claims[tr_cells].tolist()
net = ElasticNet("poisson", alpha=0.99)
lams = net.lambda_path(Xt, yt, n=25, min_ratio=1e-3)
cvp = net.cross_validate(Xt, yt, lams, splits)
fits = net.path(Xt, yt, lams)
best, simple = fits[lams.index(cvp.lam_min)], fits[lams.index(cvp.lam_1se)]
kept = [a for a, b in zip(knots, best.coefficients[1:]) if b != 0.0]
print(f"{len(knots)} steps offered, {best.df} kept at lam_min, {simple.df} at lam_1se")
print("kept:", kept)
```


    20 steps offered, 8 kept at lam_min, 5 at lam_1se
    kept: [20, 23, 26, 29, 32, 62, 65, 77]


The cross-validation curve, with the two chosen penalties marked:


``` python
import matplotlib.pyplot as plt

x = np.log10(cvp.lams)
fig, ax = plt.subplots()
ax.errorbar(x, cvp.mean, yerr=cvp.se, color="0.75", capsize=2, label="mean validation deviance")
ax.axvline(np.log10(cvp.lam_min), linestyle="--", label=f"lam_min ({best.df} steps)")
ax.axvline(np.log10(cvp.lam_1se), linestyle=":", label=f"lam_1se ({simple.df} steps)")
ax.set_xlabel("log10 of the penalty lam")
ax.set_ylabel("deviance on the validation fold")
ax.set_title("Cross-validation of the lasso on 20 age steps")
ax.legend()
```


<figure class="p-figure figure">
yNy4xOTg4NDIiIHk9IjE2Mi4wODEyMyIgc3R5bGU9ImZpbGw6IGNvbG9yLW1peChpbiBzcmdiLCB2YXIoLS1wLWluaykgMjUlLCB0cmFuc3BhcmVudCk7IHN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ZhcigtLXAtaW5rKSAyNSUsIHRyYW5zcGFyZW50KTsgc3Ryb2tlOiBjb2xvci1taXgoaW4gc3JnYiwgdmFyKC0tcC1pbmspIDI1JSwgdHJhbnNwYXJlbnQpIiAvPgogICAgIDwvZz4KICAgIDwvZz4KICAgIDxnIGlkPSJsaW5lMmRfMzQiPgogICAgIDxwYXRoIGQ9Ik0gNTYuNTk0Mjk3IDY5LjcyODEyNSAKTCA3OC41OTQyOTcgNjkuNzI4MTI1IAoiIHN0eWxlPSJmaWxsOiBub25lOyBzdHJva2U6IGNvbG9yLW1peChpbiBzcmdiLCB2YXIoLS1wLWluaykgMjUlLCB0cmFuc3BhcmVudCk7IHN0cm9rZS13aWR0aDogMS41OyBzdHJva2UtbGluZWNhcDogc3F1YXJlIiAvPgogICAgPC9nPgogICAgPGcgaWQ9ImxpbmUyZF8zNSI+PC9nPgogICAgPGcgaWQ9InRleHRfMTgiPgogICAgIDx0ZXh0IHN0eWxlPSJmb250LXNpemU6IDExcHg7IGZvbnQtZmFtaWx5OiB2YXIoLS1wLWZvbnQpOyB0ZXh0LWFuY2hvcjogc3RhcnQ7IGZpbGw6IHZhcigtLXAtaW5rKSIgeD0iODcuMzk0Mjk3IiB5PSI3My41NzgxMjUiIHRyYW5zZm9ybT0icm90YXRlKC0wIDg3LjM5NDI5NyA3My41NzgxMjUpIj5tZWFuIHZhbGlkYXRpb24gZGV2aWFuY2U8L3RleHQ+CiAgICA8L2c+CiAgIDwvZz4KICA8L2c+CiA8L2c+CiA8ZGVmcz4KICA8Y2xpcHBhdGggaWQ9InBhZjBiMGE2NjZlIj4KICAgPHJlY3QgeD0iNDYuNjk0Mjk3IiB5PSIyMi4zMTgxMjUiIHdpZHRoPSIzOTAuNiIgaGVpZ2h0PSIxOTkuNTg0IiAvPgogIDwvY2xpcHBhdGg+CiA8L2RlZnM+Cjwvc3ZnPg==" />
</figure>


The next block compares three fits with the truth by age (the exposure-weighted average of the policies' true frequencies): the lasso at [lam_min](../reference/models.CvPath.md#prospicio.models.CvPath.lam_min), the relaxed lasso (the kept steps refitted by an unpenalized [Glm](../reference/models.Glm.md#prospicio.models.Glm), section 4.5) and a P-spline GAM ([Gam](../reference/models.Gam.md#prospicio.models.Gam), which the monograph uses for its spatial second stage in chapter 8):


``` python
from prospicio.models import Gam

grid = np.arange(18, 81)
true_by_age = np.bincount(age - 18, np.exp(true_lp) * exposure) / np.bincount(age - 18, exposure)
grid_steps = Design(columns(np.ones(63), *[grid >= a for a in knots]), step_names)
lasso_curve = np.array(best.predict(grid_steps))
kept_names = ["(Intercept)"] + [f"age_stp_{a}" for a in kept]
X_kept = Design(columns(np.ones(len(cells)), *[cell_age >= a for a in kept]), kept_names, offset=cell_off)
relaxed = Glm("poisson").fit(X_kept.select(tr_cells), cell_claims[tr_cells].tolist())
relaxed_curve = np.array(relaxed.predict(Design(columns(np.ones(63), *[grid >= a for a in kept]), kept_names)))
X_age = Design(columns(np.ones(len(cells)), cell_age), ["(Intercept)", "age"], offset=cell_off)
gam_fit = Gam(Glm("poisson"), [("age", 12)]).fit(X_age.select(tr_cells), cell_claims[tr_cells].tolist())
gam_curve = np.array(gam_fit.predict(Design(columns(np.ones(63), grid), ["(Intercept)", "age"])))
ages = [18, 20, 23, 26, 35, 50, 65, 80]
(GT(pd.DataFrame({
    "age": [str(a) for a in ages],
    "truth": [true_by_age[a - 18] for a in ages],
    "lasso": [lasso_curve[a - 18] for a in ages],
    "relaxed": [relaxed_curve[a - 18] for a in ages],
    "GAM": [gam_curve[a - 18] for a in ages],
}), rowname_col="age")
 .tab_header("Claim frequency by age: truth and three fits", "Claims per policy year")
 .fmt_number(["truth", "lasso", "relaxed", "GAM"], decimals=3))
```


<style>
#tcnltedaes table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#tcnltedaes thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#tcnltedaes p { margin: 0; padding: 0; }
 #tcnltedaes .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #tcnltedaes .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #tcnltedaes .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #tcnltedaes .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #tcnltedaes .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #tcnltedaes .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #tcnltedaes .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #tcnltedaes .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #tcnltedaes .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #tcnltedaes .gt_column_spanner_outer:first-child { padding-left: 0; }
 #tcnltedaes .gt_column_spanner_outer:last-child { padding-right: 0; }
 #tcnltedaes .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #tcnltedaes .gt_spanner_row { border-bottom-style: hidden; }
 #tcnltedaes .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #tcnltedaes .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #tcnltedaes .gt_from_md> :first-child { margin-top: 0; }
 #tcnltedaes .gt_from_md> :last-child { margin-bottom: 0; }
 #tcnltedaes .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #tcnltedaes .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #tcnltedaes .gt_indent_1 { text-indent: 5px; }
 #tcnltedaes .gt_indent_2 { text-indent: calc(5px * 2); }
 #tcnltedaes .gt_indent_3 { text-indent: calc(5px * 3); }
 #tcnltedaes .gt_indent_4 { text-indent: calc(5px * 4); }
 #tcnltedaes .gt_indent_5 { text-indent: calc(5px * 5); }
 #tcnltedaes .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #tcnltedaes .gt_row_group_first td { border-top-width: 2px; }
 #tcnltedaes .gt_row_group_first th { border-top-width: 2px; }
 #tcnltedaes .gt_striped { color: #333333; background-color: #F4F4F4; }
 #tcnltedaes .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #tcnltedaes .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #tcnltedaes .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #tcnltedaes .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #tcnltedaes .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #tcnltedaes .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #tcnltedaes .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #tcnltedaes .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #tcnltedaes .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #tcnltedaes .gt_left { text-align: left; }
 #tcnltedaes .gt_center { text-align: center; }
 #tcnltedaes .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #tcnltedaes .gt_font_normal { font-weight: normal; }
 #tcnltedaes .gt_font_bold { font-weight: bold; }
 #tcnltedaes .gt_font_italic { font-style: italic; }
 #tcnltedaes .gt_super { font-size: 65%; }
 #tcnltedaes .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #tcnltedaes .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #tcnltedaes .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #tcnltedaes .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #tcnltedaes .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #tcnltedaes .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="5" id="title" class="gt_heading gt_title gt_font_normal">Claim frequency by age: truth and three fits</th>
</tr>
<tr class="gt_heading">
<th colspan="5" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Claims per policy year</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="truth" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">truth</th>
<th id="lasso" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">lasso</th>
<th id="relaxed" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">relaxed</th>
<th id="GAM" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">GAM</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">18</th>
<td class="gt_row gt_right" headers="stub-1 truth">0.565</td>
<td class="gt_row gt_right" headers="stub-1 lasso">0.531</td>
<td class="gt_row gt_right" headers="stub-1 relaxed">0.553</td>
<td class="gt_row gt_right" headers="stub-1 GAM">0.530</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">20</th>
<td class="gt_row gt_right" headers="stub-2 truth">0.481</td>
<td class="gt_row gt_right" headers="stub-2 lasso">0.408</td>
<td class="gt_row gt_right" headers="stub-2 relaxed">0.415</td>
<td class="gt_row gt_right" headers="stub-2 GAM">0.449</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">23</th>
<td class="gt_row gt_right" headers="stub-3 truth">0.363</td>
<td class="gt_row gt_right" headers="stub-3 lasso">0.304</td>
<td class="gt_row gt_right" headers="stub-3 relaxed">0.310</td>
<td class="gt_row gt_right" headers="stub-3 GAM">0.355</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">26</th>
<td class="gt_row gt_right" headers="stub-4 truth">0.264</td>
<td class="gt_row gt_right" headers="stub-4 lasso">0.256</td>
<td class="gt_row gt_right" headers="stub-4 relaxed">0.260</td>
<td class="gt_row gt_right" headers="stub-4 GAM">0.290</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">35</th>
<td class="gt_row gt_right" headers="stub-5 truth">0.216</td>
<td class="gt_row gt_right" headers="stub-5 lasso">0.207</td>
<td class="gt_row gt_right" headers="stub-5 relaxed">0.200</td>
<td class="gt_row gt_right" headers="stub-5 GAM">0.206</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">50</th>
<td class="gt_row gt_right" headers="stub-6 truth">0.207</td>
<td class="gt_row gt_right" headers="stub-6 lasso">0.207</td>
<td class="gt_row gt_right" headers="stub-6 relaxed">0.200</td>
<td class="gt_row gt_right" headers="stub-6 GAM">0.195</td>
</tr>
<tr>
<th id="stub-7" class="gt_row gt_left gt_stub" scope="row">65</th>
<td class="gt_row gt_right" headers="stub-7 truth">0.215</td>
<td class="gt_row gt_right" headers="stub-7 lasso">0.236</td>
<td class="gt_row gt_right" headers="stub-7 relaxed">0.239</td>
<td class="gt_row gt_right" headers="stub-7 GAM">0.228</td>
</tr>
<tr>
<th id="stub-8" class="gt_row gt_left gt_stub" scope="row">80</th>
<td class="gt_row gt_right" headers="stub-8 truth">0.256</td>
<td class="gt_row gt_right" headers="stub-8 lasso">0.239</td>
<td class="gt_row gt_right" headers="stub-8 relaxed">0.253</td>
<td class="gt_row gt_right" headers="stub-8 GAM">0.249</td>
</tr>
</tbody>
</table>


``` python
print(f"GAM effective degrees of freedom {gam_fit.edf:.1f}")
```


    GAM effective degrees of freedom 5.7


``` python
fig, ax = plt.subplots()
ax.plot(grid, true_by_age, color="0.75", linewidth=3, label="truth")
ax.plot(grid, lasso_curve, label="lasso at lam_min")
ax.plot(grid, relaxed_curve, label="relaxed lasso")
ax.plot(grid, gam_curve, label="GAM")
ax.set_xlabel("driver age (years)")
ax.set_ylabel("claims per policy year")
ax.set_title("Claim frequency by age: truth and three fits")
ax.legend()
```


<figure class="p-figure figure">
<img src="data:image/svg+xml;base64,PHN2ZyB4bGluaz0iaHR0cDov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EyNSkiPnJlbGF4ZWQgbGFzc288L3RleHQ+CiAgICA8L2c+CiAgICA8ZyBpZD0ibGluZTJkXzM4Ij4KICAgICA8cGF0aCBkPSJNIDMxMC44MDYzMjggODYuMjI4OTg0IApMIDMyMS44MDYzMjggODYuMjI4OTg0IApMIDMzMi44MDYzMjggODYuMjI4OTg0IAoiIHN0eWxlPSJmaWxsOiBub25lOyBzdHJva2U6IHZhcigtLXAtc2VyaWVzLTMpOyBzdHJva2Utd2lkdGg6IDEuNTsgc3Ryb2tlLWxpbmVjYXA6IHNxdWFyZSIgLz4KICAgIDwvZz4KICAgIDxnIGlkPSJ0ZXh0XzIyIj4KICAgICA8dGV4dCBzdHlsZT0iZm9udC1zaXplOiAxMXB4OyBmb250LWZhbWlseTogdmFyKC0tcC1mb250KTsgdGV4dC1hbmNob3I6IHN0YXJ0OyBmaWxsOiB2YXIoLS1wLWluaykiIHg9IjM0MS42MDYzMjgiIHk9IjkwLjA3ODk4NCIgdHJhbnNmb3JtPSJyb3RhdGUoLTAgMzQxLjYwNjMyOCA5MC4wNzg5ODQpIj5HQU08L3RleHQ+CiAgICA8L2c+CiAgIDwvZz4KICA8L2c+CiA8L2c+CiA8ZGVmcz4KICA8Y2xpcHBhdGggaWQ9InBhMzI4YmUwM2E5Ij4KICAgPHJlY3QgeD0iNTMuNjkzMDQ3IiB5PSIyMi4zMTgxMjUiIHdpZHRoPSIzOTAuNiIgaGVpZ2h0PSIxOTkuNTg0IiAvPgogIDwvY2xpcHBhdGg+CiA8L2RlZnM+Cjwvc3ZnPg==" />
</figure>


All three fits find the young-driver slope and the rise after 60 without being told where they are. Lasso shrinkage pulls the extremes towards the middle (as section 5.2 sees above aircraft age 20), and the relaxed fit removes part of that. The monograph prefers steps and hinges because the result is a short rating table. A GAM gives a smooth curve, which you tabulate afterwards.

Section 5.8.1 links steps to the fused lasso. A step at each level is the same model as a dummy at each level, and each step coefficient is the difference between neighbouring dummies. So a lasso penalty on steps penalizes the jumps between neighbours.


## 3.3 Monotone effects

Section 5.7.2 makes an ordinal effect monotone with non-negative step coefficients. A GAM can set the shape directly: `"mpd"` is a monotone decreasing P-spline (from scam). The block fits it to vehicle age, whose true effect falls until age 6 and is flat after:


``` python
veh_cells, veh_cell = np.unique(veh_age * 10 + fold, return_inverse=True)
veh_train = rows(veh_cells % 10 < 7)
X_veh = Design(columns(np.ones(len(veh_cells)), veh_cells // 10), ["(Intercept)", "veh_age"],
               offset=np.log(np.bincount(veh_cell, exposure)).tolist())
mono = Gam(Glm("poisson"), [{"column": "veh_age", "n_basis": 8, "bs": "mpd"}]).fit(
    X_veh.select(veh_train), np.bincount(veh_cell, claims)[veh_train].tolist())
curve = np.array(mono.predict(Design(columns(np.ones(21), np.arange(21)), ["(Intercept)", "veh_age"])))
show = [0, 2, 4, 6, 10, 15, 20]
(GT(pd.DataFrame({
    "vehicle age": [str(v) for v in show],
    "fitted": (curve / curve[0])[show],
    "true": [math.exp(-0.08 * min(v, 6)) for v in show],
}), rowname_col="vehicle age")
 .tab_header("Relativity of claim frequency to vehicle age 0", "Monotone P-spline against the true effect")
 .fmt_number(["fitted", "true"], decimals=2))
```


<style>
#fqxrhohkuv table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#fqxrhohkuv thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#fqxrhohkuv p { margin: 0; padding: 0; }
 #fqxrhohkuv .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #fqxrhohkuv .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #fqxrhohkuv .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #fqxrhohkuv .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #fqxrhohkuv .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fqxrhohkuv .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fqxrhohkuv .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fqxrhohkuv .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #fqxrhohkuv .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #fqxrhohkuv .gt_column_spanner_outer:first-child { padding-left: 0; }
 #fqxrhohkuv .gt_column_spanner_outer:last-child { padding-right: 0; }
 #fqxrhohkuv .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #fqxrhohkuv .gt_spanner_row { border-bottom-style: hidden; }
 #fqxrhohkuv .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #fqxrhohkuv .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #fqxrhohkuv .gt_from_md> :first-child { margin-top: 0; }
 #fqxrhohkuv .gt_from_md> :last-child { margin-bottom: 0; }
 #fqxrhohkuv .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #fqxrhohkuv .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #fqxrhohkuv .gt_indent_1 { text-indent: 5px; }
 #fqxrhohkuv .gt_indent_2 { text-indent: calc(5px * 2); }
 #fqxrhohkuv .gt_indent_3 { text-indent: calc(5px * 3); }
 #fqxrhohkuv .gt_indent_4 { text-indent: calc(5px * 4); }
 #fqxrhohkuv .gt_indent_5 { text-indent: calc(5px * 5); }
 #fqxrhohkuv .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #fqxrhohkuv .gt_row_group_first td { border-top-width: 2px; }
 #fqxrhohkuv .gt_row_group_first th { border-top-width: 2px; }
 #fqxrhohkuv .gt_striped { color: #333333; background-color: #F4F4F4; }
 #fqxrhohkuv .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fqxrhohkuv .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fqxrhohkuv .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #fqxrhohkuv .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fqxrhohkuv .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fqxrhohkuv .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #fqxrhohkuv .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #fqxrhohkuv .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fqxrhohkuv .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fqxrhohkuv .gt_left { text-align: left; }
 #fqxrhohkuv .gt_center { text-align: center; }
 #fqxrhohkuv .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #fqxrhohkuv .gt_font_normal { font-weight: normal; }
 #fqxrhohkuv .gt_font_bold { font-weight: bold; }
 #fqxrhohkuv .gt_font_italic { font-style: italic; }
 #fqxrhohkuv .gt_super { font-size: 65%; }
 #fqxrhohkuv .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fqxrhohkuv .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #fqxrhohkuv .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fqxrhohkuv .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fqxrhohkuv .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #fqxrhohkuv .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Relativity of claim frequency to vehicle age 0</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Monotone P-spline against the true effect</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="fitted" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">fitted</th>
<th id="true" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">true</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">0</th>
<td class="gt_row gt_right" headers="stub-1 fitted">1.00</td>
<td class="gt_row gt_right" headers="stub-1 true">1.00</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">2</th>
<td class="gt_row gt_right" headers="stub-2 fitted">0.89</td>
<td class="gt_row gt_right" headers="stub-2 true">0.85</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">4</th>
<td class="gt_row gt_right" headers="stub-3 fitted">0.80</td>
<td class="gt_row gt_right" headers="stub-3 true">0.73</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">6</th>
<td class="gt_row gt_right" headers="stub-4 fitted">0.75</td>
<td class="gt_row gt_right" headers="stub-4 true">0.62</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">10</th>
<td class="gt_row gt_right" headers="stub-5 fitted">0.70</td>
<td class="gt_row gt_right" headers="stub-5 true">0.62</td>
</tr>
<tr>
<th id="stub-6" class="gt_row gt_left gt_stub" scope="row">15</th>
<td class="gt_row gt_right" headers="stub-6 fitted">0.64</td>
<td class="gt_row gt_right" headers="stub-6 true">0.62</td>
</tr>
<tr>
<th id="stub-7" class="gt_row gt_left gt_stub" scope="row">20</th>
<td class="gt_row gt_right" headers="stub-7 fitted">0.61</td>
<td class="gt_row gt_right" headers="stub-7 true">0.62</td>
</tr>
</tbody>
</table>


The monotone fit bends more gradually than the true hinge and keeps falling a little after age 6, but it cannot turn back up. A constraint hides a reversal if the data has one, so use it where the shape is known (claim history, deductibles), not to make a factor look tidy.


# 4. High cardinality categorical variables (chapter 6)


## 4.1 Target encoding, and keeping it out of its own fold

A factor with thousands of levels (aircraft make, city, zip code) is a problem as dummies in a GLM: it uses much memory and gives unstable estimates for thin levels. Target encoding, the main tool of chapter 6, replaces each level by one number, its actual-to-expected ratio shrunk towards 1 by the credibility factor `z = n / (n + K)`, where [n](../reference/pricing.TrendFit.md#prospicio.pricing.TrendFit.n) is the level's exposure. The log of that number is the feature.

Encoding a level from its own records leaks the target into the feature (section 6.3), so a record in fold [k](../reference/models.TargetEncoding.md#prospicio.models.TargetEncoding.k) is encoded only from the other folds. Table 6.1 has one make with six aircraft in three folds:


``` python
te_fold = np.array([1, 1, 2, 2, 3, 3])
te_acc = np.array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0])
encodings = []
for k, printed in zip([1, 2, 3], [0.75, 0.50, 0.25]):
    other = te_fold != k
    encodings.append({"fold": str(k), "accidents elsewhere": te_acc[other].sum(), "aircraft elsewhere": other.sum(),
                      "encoding": te_acc[other].mean(), "book": printed})
(GT(pd.DataFrame(encodings), rowname_col="fold")
 .tab_header("Table 6.1: each fold encoded from the other folds")
 .fmt_integer(["accidents elsewhere", "aircraft elsewhere"])
 .fmt_number(["encoding", "book"], decimals=2))
```


<style>
#sihctfquhc table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#sihctfquhc thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#sihctfquhc p { margin: 0; padding: 0; }
 #sihctfquhc .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #sihctfquhc .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #sihctfquhc .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #sihctfquhc .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #sihctfquhc .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #sihctfquhc .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #sihctfquhc .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #sihctfquhc .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #sihctfquhc .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #sihctfquhc .gt_column_spanner_outer:first-child { padding-left: 0; }
 #sihctfquhc .gt_column_spanner_outer:last-child { padding-right: 0; }
 #sihctfquhc .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #sihctfquhc .gt_spanner_row { border-bottom-style: hidden; }
 #sihctfquhc .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #sihctfquhc .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #sihctfquhc .gt_from_md> :first-child { margin-top: 0; }
 #sihctfquhc .gt_from_md> :last-child { margin-bottom: 0; }
 #sihctfquhc .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #sihctfquhc .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #sihctfquhc .gt_indent_1 { text-indent: 5px; }
 #sihctfquhc .gt_indent_2 { text-indent: calc(5px * 2); }
 #sihctfquhc .gt_indent_3 { text-indent: calc(5px * 3); }
 #sihctfquhc .gt_indent_4 { text-indent: calc(5px * 4); }
 #sihctfquhc .gt_indent_5 { text-indent: calc(5px * 5); }
 #sihctfquhc .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #sihctfquhc .gt_row_group_first td { border-top-width: 2px; }
 #sihctfquhc .gt_row_group_first th { border-top-width: 2px; }
 #sihctfquhc .gt_striped { color: #333333; background-color: #F4F4F4; }
 #sihctfquhc .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #sihctfquhc .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #sihctfquhc .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #sihctfquhc .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #sihctfquhc .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #sihctfquhc .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #sihctfquhc .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #sihctfquhc .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #sihctfquhc .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #sihctfquhc .gt_left { text-align: left; }
 #sihctfquhc .gt_center { text-align: center; }
 #sihctfquhc .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #sihctfquhc .gt_font_normal { font-weight: normal; }
 #sihctfquhc .gt_font_bold { font-weight: bold; }
 #sihctfquhc .gt_font_italic { font-style: italic; }
 #sihctfquhc .gt_super { font-size: 65%; }
 #sihctfquhc .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #sihctfquhc .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #sihctfquhc .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #sihctfquhc .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #sihctfquhc .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #sihctfquhc .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="5" id="title" class="gt_heading gt_title gt_font_normal">Table 6.1: each fold encoded from the other folds</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="accidents-elsewhere" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">accidents elsewhere</th>
<th id="aircraft-elsewhere" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">aircraft elsewhere</th>
<th id="encoding" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">encoding</th>
<th id="book" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">1</th>
<td class="gt_row gt_right" headers="stub-1 accidents-elsewhere">3</td>
<td class="gt_row gt_right" headers="stub-1 aircraft-elsewhere">4</td>
<td class="gt_row gt_right" headers="stub-1 encoding">0.75</td>
<td class="gt_row gt_right" headers="stub-1 book">0.75</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">2</th>
<td class="gt_row gt_right" headers="stub-2 accidents-elsewhere">2</td>
<td class="gt_row gt_right" headers="stub-2 aircraft-elsewhere">4</td>
<td class="gt_row gt_right" headers="stub-2 encoding">0.50</td>
<td class="gt_row gt_right" headers="stub-2 book">0.50</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">3</th>
<td class="gt_row gt_right" headers="stub-3 accidents-elsewhere">1</td>
<td class="gt_row gt_right" headers="stub-3 aircraft-elsewhere">4</td>
<td class="gt_row gt_right" headers="stub-3 encoding">0.25</td>
<td class="gt_row gt_right" headers="stub-3 book">0.25</td>
</tr>
</tbody>
</table>


## 4.2 The credibility constant, and the printed encodings

Section 6.6 estimates `K` as the ratio of the within-make variance (an aircraft-year's accident count, Bernoulli at the mean rate 0.004584) to the between-make variance, which the monograph estimates from the mean residuals of large makes as 7.038492e-6:


``` python
p = 0.004584
within = p * (1 - p)
K_est = within / 7.038492e-6
(GT(pd.DataFrame({
    "quantity": ["within variance", "K", "credibility at 1,000 aircraft-years"],
    "prospicio": [within, K_est, 1000 / (1000 + 648)],
    "book": ["0.004562987", "648", "0.61"],
}), rowname_col="quantity")
 .tab_header("Section 6.6: the credibility constant")
 .fmt_number("prospicio", rows=[0], decimals=9)
 .fmt_number("prospicio", rows=[1], decimals=0)
 .fmt_number("prospicio", rows=[2], decimals=2))
```


<style>
#kdycxxsnoo table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#kdycxxsnoo thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#kdycxxsnoo p { margin: 0; padding: 0; }
 #kdycxxsnoo .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #kdycxxsnoo .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #kdycxxsnoo .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #kdycxxsnoo .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #kdycxxsnoo .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #kdycxxsnoo .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #kdycxxsnoo .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #kdycxxsnoo .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #kdycxxsnoo .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #kdycxxsnoo .gt_column_spanner_outer:first-child { padding-left: 0; }
 #kdycxxsnoo .gt_column_spanner_outer:last-child { padding-right: 0; }
 #kdycxxsnoo .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #kdycxxsnoo .gt_spanner_row { border-bottom-style: hidden; }
 #kdycxxsnoo .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #kdycxxsnoo .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #kdycxxsnoo .gt_from_md> :first-child { margin-top: 0; }
 #kdycxxsnoo .gt_from_md> :last-child { margin-bottom: 0; }
 #kdycxxsnoo .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #kdycxxsnoo .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #kdycxxsnoo .gt_indent_1 { text-indent: 5px; }
 #kdycxxsnoo .gt_indent_2 { text-indent: calc(5px * 2); }
 #kdycxxsnoo .gt_indent_3 { text-indent: calc(5px * 3); }
 #kdycxxsnoo .gt_indent_4 { text-indent: calc(5px * 4); }
 #kdycxxsnoo .gt_indent_5 { text-indent: calc(5px * 5); }
 #kdycxxsnoo .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #kdycxxsnoo .gt_row_group_first td { border-top-width: 2px; }
 #kdycxxsnoo .gt_row_group_first th { border-top-width: 2px; }
 #kdycxxsnoo .gt_striped { color: #333333; background-color: #F4F4F4; }
 #kdycxxsnoo .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #kdycxxsnoo .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #kdycxxsnoo .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #kdycxxsnoo .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #kdycxxsnoo .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #kdycxxsnoo .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #kdycxxsnoo .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #kdycxxsnoo .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #kdycxxsnoo .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #kdycxxsnoo .gt_left { text-align: left; }
 #kdycxxsnoo .gt_center { text-align: center; }
 #kdycxxsnoo .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #kdycxxsnoo .gt_font_normal { font-weight: normal; }
 #kdycxxsnoo .gt_font_bold { font-weight: bold; }
 #kdycxxsnoo .gt_font_italic { font-style: italic; }
 #kdycxxsnoo .gt_super { font-size: 65%; }
 #kdycxxsnoo .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #kdycxxsnoo .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #kdycxxsnoo .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #kdycxxsnoo .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #kdycxxsnoo .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #kdycxxsnoo .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Section 6.6: the credibility constant</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="prospicio" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">prospicio</th>
<th id="book" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">within variance</th>
<td class="gt_row gt_right" headers="stub-1 prospicio">0.004562987</td>
<td class="gt_row gt_right" headers="stub-1 book">0.004562987</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">K</th>
<td class="gt_row gt_right" headers="stub-2 prospicio">648</td>
<td class="gt_row gt_right" headers="stub-2 book">648</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">credibility at 1,000 aircraft-years</th>
<td class="gt_row gt_right" headers="stub-3 prospicio">0.61</td>
<td class="gt_row gt_right" headers="stub-3 book">0.61</td>
</tr>
</tbody>
</table>


Table 6.5 lists encoded makes at `K` = 1,024, the monograph's final value. The next block recomputes them from the printed inputs:


``` python
table_6_5 = [("DJI", 11900, 0.0, 0.9208, 0.079), ("TEXTRON AVIATION INC", 5483, 0.24356, 0.8426, 0.363),
             ("MARLIN JOHN E", 13, 186.59373, 0.0122, 3.266), ("STUMP GREAT LAKES", 12, 223.74936, 0.0116, 3.579)]
encoded = []
for make_name, expo, ave, z_printed, te_printed in table_6_5:
    z = expo / (expo + 1024)
    encoded.append({"make": make_name, "z": z, "book z": z_printed, "encoding": 1 - z + z * ave,
                    "from book z": 1 - z_printed + z_printed * ave, "book encoding": te_printed})
(GT(pd.DataFrame(encoded), rowname_col="make")
 .tab_header("Table 6.5: encoded makes at K = 1,024")
 .fmt_number(["z", "book z"], decimals=4)
 .fmt_number(["encoding", "from book z", "book encoding"], decimals=3))
```


<style>
#hbagggejac table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#hbagggejac thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#hbagggejac p { margin: 0; padding: 0; }
 #hbagggejac .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #hbagggejac .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #hbagggejac .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #hbagggejac .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #hbagggejac .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #hbagggejac .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #hbagggejac .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #hbagggejac .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #hbagggejac .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #hbagggejac .gt_column_spanner_outer:first-child { padding-left: 0; }
 #hbagggejac .gt_column_spanner_outer:last-child { padding-right: 0; }
 #hbagggejac .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #hbagggejac .gt_spanner_row { border-bottom-style: hidden; }
 #hbagggejac .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #hbagggejac .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #hbagggejac .gt_from_md> :first-child { margin-top: 0; }
 #hbagggejac .gt_from_md> :last-child { margin-bottom: 0; }
 #hbagggejac .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #hbagggejac .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #hbagggejac .gt_indent_1 { text-indent: 5px; }
 #hbagggejac .gt_indent_2 { text-indent: calc(5px * 2); }
 #hbagggejac .gt_indent_3 { text-indent: calc(5px * 3); }
 #hbagggejac .gt_indent_4 { text-indent: calc(5px * 4); }
 #hbagggejac .gt_indent_5 { text-indent: calc(5px * 5); }
 #hbagggejac .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #hbagggejac .gt_row_group_first td { border-top-width: 2px; }
 #hbagggejac .gt_row_group_first th { border-top-width: 2px; }
 #hbagggejac .gt_striped { color: #333333; background-color: #F4F4F4; }
 #hbagggejac .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #hbagggejac .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #hbagggejac .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #hbagggejac .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #hbagggejac .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #hbagggejac .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #hbagggejac .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #hbagggejac .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #hbagggejac .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #hbagggejac .gt_left { text-align: left; }
 #hbagggejac .gt_center { text-align: center; }
 #hbagggejac .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #hbagggejac .gt_font_normal { font-weight: normal; }
 #hbagggejac .gt_font_bold { font-weight: bold; }
 #hbagggejac .gt_font_italic { font-style: italic; }
 #hbagggejac .gt_super { font-size: 65%; }
 #hbagggejac .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #hbagggejac .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #hbagggejac .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #hbagggejac .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #hbagggejac .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #hbagggejac .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="6" id="title" class="gt_heading gt_title gt_font_normal">Table 6.5: encoded makes at K = 1,024</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="z" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">z</th>
<th id="book-z" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book z</th>
<th id="encoding" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">encoding</th>
<th id="from-book-z" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">from book z</th>
<th id="book-encoding" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">book encoding</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">DJI</th>
<td class="gt_row gt_right" headers="stub-1 z">0.9208</td>
<td class="gt_row gt_right" headers="stub-1 book-z">0.9208</td>
<td class="gt_row gt_right" headers="stub-1 encoding">0.079</td>
<td class="gt_row gt_right" headers="stub-1 from-book-z">0.079</td>
<td class="gt_row gt_right" headers="stub-1 book-encoding">0.079</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">TEXTRON AVIATION INC</th>
<td class="gt_row gt_right" headers="stub-2 z">0.8426</td>
<td class="gt_row gt_right" headers="stub-2 book-z">0.8426</td>
<td class="gt_row gt_right" headers="stub-2 encoding">0.363</td>
<td class="gt_row gt_right" headers="stub-2 from-book-z">0.363</td>
<td class="gt_row gt_right" headers="stub-2 book-encoding">0.363</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">MARLIN JOHN E</th>
<td class="gt_row gt_right" headers="stub-3 z">0.0125</td>
<td class="gt_row gt_right" headers="stub-3 book-z">0.0122</td>
<td class="gt_row gt_right" headers="stub-3 encoding">3.327</td>
<td class="gt_row gt_right" headers="stub-3 from-book-z">3.264</td>
<td class="gt_row gt_right" headers="stub-3 book-encoding">3.266</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">STUMP GREAT LAKES</th>
<td class="gt_row gt_right" headers="stub-4 z">0.0116</td>
<td class="gt_row gt_right" headers="stub-4 book-z">0.0116</td>
<td class="gt_row gt_right" headers="stub-4 encoding">3.580</td>
<td class="gt_row gt_right" headers="stub-4 from-book-z">3.584</td>
<td class="gt_row gt_right" headers="stub-4 book-encoding">3.579</td>
</tr>
</tbody>
</table>


DJI and Textron match. Marlin's printed credibility (0.0122) implies about 12.65 aircraft-years, not 13, so the exposure column is rounded (the encoding from the printed [z](../reference/reserving.CalendarYearTest.md#prospicio.reserving.CalendarYearTest.z) is 3.264). Stump Great Lakes differs for the same reason.

Section 6.7.1's worked sentence multiplies Stump's [z](../reference/reserving.CalendarYearTest.md#prospicio.reserving.CalendarYearTest.z) by 222.22, but Table 6.5 has 223.75, which gives the printed 3.58: the text is wrong. The table's caption also describes AvE as predicted over actual, but its values are actual over expected.

Two smaller checks come from the same chapter: the Bell helicopter example of section 6.7.2 (16 per thousand against 4 for the overall mean, against 20 for the GLM prediction for helicopters), and the logistic blending of section 6.7.6 at a level with no data, which should get no credibility but gets some:


``` python
print(f"Bell: {16 / 4:.2f} against the mean, {16 / 20:.2f} against the GLM (printed 4 and 0.80)")
for smoothing in [100, 500]:
    print(f"logistic credibility at n = 0, inflection 500, smoothing {smoothing}: "
          f"{1 / (1 + math.exp((500 - 0) / smoothing)):.3f}")
```


    Bell: 4.00 against the mean, 0.80 against the GLM (printed 4 and 0.80)
    logistic credibility at n = 0, inflection 500, smoothing 100: 0.007
    logistic credibility at n = 0, inflection 500, smoothing 500: 0.269


The second value is section 6.7.6's "about 25%" for a level with no data.


## 4.3 Ridge regression on dummies is credibility

Section 6.8.1: ridge on the dummies of one factor, with a centred normal response and no intercept, gives each level the coefficient `n_k (mean_k - mean) / (n_k + lambda)`, a credibility-weighted deviation from the overall mean. prospicio minimizes the mean squared error over two plus [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) over two times the sum of squares, so the monograph's `lambda` is [lam](../reference/models.ElasticNet.md#prospicio.models.ElasticNet.lam) times the number of records. A design with no all-ones column has no intercept, so [ElasticNet](../reference/models.ElasticNet.md#prospicio.models.ElasticNet) fits exactly that model:


``` python
sizes = [1, 5, 50, 400]
levels = np.repeat(np.arange(4), sizes)
y_lvl = rng.normal(np.array([2.0, -1.0, 0.5, 0.0])[levels], 1.0)
yc = y_lvl - y_lvl.mean()
dummies = [(levels == j).astype(float) for j in range(4)]
lam = 0.1
fit = ElasticNet("gaussian", alpha=0.0, lam=lam, standardize=False).fit(
    Design(columns(*dummies), [f"level{j}" for j in range(4)]), yc.tolist())
K = lam * len(yc)
ridge_rows = []
for j, size in enumerate(sizes):
    z = size / (size + K)
    ridge_rows.append({"level": f"level {j}", "records": size, "ridge": fit.coefficients[j],
                       "z x deviation": z * yc[levels == j].mean(), "z": z})
(GT(pd.DataFrame(ridge_rows), rowname_col="level")
 .tab_header("Section 6.8.1: ridge on dummies is credibility", f"lam = {lam}, so lambda = {K:.1f}")
 .fmt_integer("records")
 .fmt_number(["ridge", "z x deviation"], decimals=4, force_sign=True)
 .fmt_number("z", decimals=3))
```


<style>
#ubnbbacdcl table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#ubnbbacdcl thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#ubnbbacdcl p { margin: 0; padding: 0; }
 #ubnbbacdcl .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #ubnbbacdcl .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #ubnbbacdcl .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #ubnbbacdcl .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #ubnbbacdcl .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ubnbbacdcl .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ubnbbacdcl .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #ubnbbacdcl .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #ubnbbacdcl .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #ubnbbacdcl .gt_column_spanner_outer:first-child { padding-left: 0; }
 #ubnbbacdcl .gt_column_spanner_outer:last-child { padding-right: 0; }
 #ubnbbacdcl .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #ubnbbacdcl .gt_spanner_row { border-bottom-style: hidden; }
 #ubnbbacdcl .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #ubnbbacdcl .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #ubnbbacdcl .gt_from_md> :first-child { margin-top: 0; }
 #ubnbbacdcl .gt_from_md> :last-child { margin-bottom: 0; }
 #ubnbbacdcl .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #ubnbbacdcl .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #ubnbbacdcl .gt_indent_1 { text-indent: 5px; }
 #ubnbbacdcl .gt_indent_2 { text-indent: calc(5px * 2); }
 #ubnbbacdcl .gt_indent_3 { text-indent: calc(5px * 3); }
 #ubnbbacdcl .gt_indent_4 { text-indent: calc(5px * 4); }
 #ubnbbacdcl .gt_indent_5 { text-indent: calc(5px * 5); }
 #ubnbbacdcl .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #ubnbbacdcl .gt_row_group_first td { border-top-width: 2px; }
 #ubnbbacdcl .gt_row_group_first th { border-top-width: 2px; }
 #ubnbbacdcl .gt_striped { color: #333333; background-color: #F4F4F4; }
 #ubnbbacdcl .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ubnbbacdcl .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ubnbbacdcl .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #ubnbbacdcl .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #ubnbbacdcl .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #ubnbbacdcl .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #ubnbbacdcl .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #ubnbbacdcl .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ubnbbacdcl .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ubnbbacdcl .gt_left { text-align: left; }
 #ubnbbacdcl .gt_center { text-align: center; }
 #ubnbbacdcl .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #ubnbbacdcl .gt_font_normal { font-weight: normal; }
 #ubnbbacdcl .gt_font_bold { font-weight: bold; }
 #ubnbbacdcl .gt_font_italic { font-style: italic; }
 #ubnbbacdcl .gt_super { font-size: 65%; }
 #ubnbbacdcl .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ubnbbacdcl .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #ubnbbacdcl .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #ubnbbacdcl .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #ubnbbacdcl .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #ubnbbacdcl .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="5" id="title" class="gt_heading gt_title gt_font_normal">Section 6.8.1: ridge on dummies is credibility</th>
</tr>
<tr class="gt_heading">
<th colspan="5" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">lam = 0.1, so lambda = 45.6</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="records" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">records</th>
<th id="ridge" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">ridge</th>
<th id="z-x-deviation" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">z x deviation</th>
<th id="z" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">z</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">level 0</th>
<td class="gt_row gt_right" headers="stub-1 records">1</td>
<td class="gt_row gt_right" headers="stub-1 ridge">+0.0456</td>
<td class="gt_row gt_right" headers="stub-1 z-x-deviation">+0.0456</td>
<td class="gt_row gt_right" headers="stub-1 z">0.021</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">level 1</th>
<td class="gt_row gt_right" headers="stub-2 records">5</td>
<td class="gt_row gt_right" headers="stub-2 ridge">−0.0470</td>
<td class="gt_row gt_right" headers="stub-2 z-x-deviation">−0.0470</td>
<td class="gt_row gt_right" headers="stub-2 z">0.099</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">level 2</th>
<td class="gt_row gt_right" headers="stub-3 records">50</td>
<td class="gt_row gt_right" headers="stub-3 ridge">+0.2407</td>
<td class="gt_row gt_right" headers="stub-3 z-x-deviation">+0.2407</td>
<td class="gt_row gt_right" headers="stub-3 z">0.523</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">level 3</th>
<td class="gt_row gt_right" headers="stub-4 records">400</td>
<td class="gt_row gt_right" headers="stub-4 ridge">−0.0511</td>
<td class="gt_row gt_right" headers="stub-4 z-x-deviation">−0.0511</td>
<td class="gt_row gt_right" headers="stub-4 z">0.898</td>
</tr>
</tbody>
</table>


The penalty does the work of the Buhlmann `K`. Credibility theory estimates `K` from variance components; penalized regression chooses it by cross-validation.


## 4.4 Target encoding the portfolio's 300 makes

On the portfolio, the encoding follows section 6.7.2. A cross-fitted first GLM without make gives each policy's expected count, so no model predicts a record that it saw in training. A make's encoding is its shrunk actual-to-expected ratio, and its log goes into a second-stage GLM with the first-GLM prediction as offset (section 6.9). For each `K`, seven-fold cross-validation repeats the whole procedure inside each fold:


``` python
expected = np.zeros(n)
for j in range(7):
    fit_j = Glm("poisson").fit(X_base.select(rows(train & (fold != j))), claims[train & (fold != j)].tolist())
    expected[fold == j] = fit_j.predict(X_base.select(rows(fold == j)))
expected[~train] = Glm("poisson").fit(X_base.select(rows(train)), claims[train].tolist()).predict(
    X_base.select(rows(~train)))


def encode(source, K):
    """Each make's shrunk actual-to-expected ratio from the rows in `source`."""
    actual = np.bincount(make[source], claims[source], minlength=300)
    exp_ = np.bincount(make[source], expected[source], minlength=300)
    expo = np.bincount(make[source], exposure[source], minlength=300)
    z = expo / (expo + K)
    return 1 - z + z * np.divide(actual, exp_, out=np.ones(300), where=exp_ > 0)


def make_feature(K, held_out=None):
    """Per policy: a training row in fold j is encoded from the training folds other than j
    (and other than the held-out fold); every other row from all training folds but the held-out one."""
    te = encode(train & (fold != held_out), K)[make]
    for j in range(7):
        if j != held_out:
            te[fold == j] = encode(train & (fold != j) & (fold != held_out), K)[make[fold == j]]
    return np.log(te)


stage1 = {}
for k in range(7):
    fit_k = Glm("poisson").fit(X_base.select(rows(train & (fold != k))), claims[train & (fold != k)].tolist())
    stage1[k] = np.asarray(fit_k.predict(X_base))
results = []
for K in [16, 64, 256, 1024, 4096]:
    scores, betas = [], []
    for k in range(7):
        feature = make_feature(K, k)
        X2 = Design(columns(ones, feature), ["(Intercept)", "log_te"], offset=np.log(stage1[k]).tolist())
        fit_rows, val = rows(train & (fold != k)), rows(fold == k)
        fit2 = Glm("poisson").fit(X2.select(fit_rows), claims[fit_rows].tolist())
        scores.append(pseudo_r2(claims[val], fit2.predict(X2.select(val)), exposure[val]))
        betas.append(fit2.coefficients[1])
    results.append({"K": str(K), "cv pseudo-R2": np.mean(scores), "coefficient": np.mean(betas)})
(GT(pd.DataFrame(results), rowname_col="K")
 .tab_header("Target encoding of the 300 makes", "Second-stage GLM by credibility constant K")
 .fmt_number("cv pseudo-R2", decimals=3)
 .fmt_number("coefficient", decimals=2))
```


<style>
#fhtpstugap table {
          font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', 'Fira Sans', 'Droid Sans', Arial, sans-serif;
          -webkit-font-smoothing: antialiased;
          -moz-osx-font-smoothing: grayscale;
        }

#fhtpstugap thead, tbody, tfoot, tr, td, th { border-style: none; }
 tr { background-color: transparent; }
#fhtpstugap p { margin: 0; padding: 0; }
 #fhtpstugap .gt_table { display: table; border-collapse: collapse; line-height: normal; margin-left: auto; margin-right: auto; color: #333333; font-size: 16px; font-weight: normal; font-style: normal; background-color: #FFFFFF; width: auto; border-top-style: solid; border-top-width: 2px; border-top-color: #A8A8A8; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #A8A8A8; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; }
 #fhtpstugap .gt_caption { padding-top: 4px; padding-bottom: 4px; }
 #fhtpstugap .gt_title { color: #333333; font-size: 125%; font-weight: initial; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; border-bottom-color: #FFFFFF; border-bottom-width: 0; }
 #fhtpstugap .gt_subtitle { color: #333333; font-size: 85%; font-weight: initial; padding-top: 3px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; border-top-color: #FFFFFF; border-top-width: 0; }
 #fhtpstugap .gt_heading { background-color: #FFFFFF; text-align: center; border-bottom-color: #FFFFFF; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fhtpstugap .gt_bottom_border { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fhtpstugap .gt_col_headings { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; }
 #fhtpstugap .gt_col_heading { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; overflow-x: hidden; }
 #fhtpstugap .gt_column_spanner_outer { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: normal; text-transform: inherit; padding-top: 0; padding-bottom: 0; padding-left: 4px; padding-right: 4px; }
 #fhtpstugap .gt_column_spanner_outer:first-child { padding-left: 0; }
 #fhtpstugap .gt_column_spanner_outer:last-child { padding-right: 0; }
 #fhtpstugap .gt_column_spanner { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: bottom; padding-top: 5px; padding-bottom: 5px; overflow-x: hidden; display: inline-block; width: 100%; }
 #fhtpstugap .gt_spanner_row { border-bottom-style: hidden; }
 #fhtpstugap .gt_group_heading { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; text-align: left; }
 #fhtpstugap .gt_empty_group_heading { padding: 0.5px; color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; vertical-align: middle; }
 #fhtpstugap .gt_from_md> :first-child { margin-top: 0; }
 #fhtpstugap .gt_from_md> :last-child { margin-bottom: 0; }
 #fhtpstugap .gt_row { padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; margin: 10px; border-top-style: solid; border-top-width: 1px; border-top-color: #D3D3D3; border-left-style: none; border-left-width: 1px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 1px; border-right-color: #D3D3D3; vertical-align: middle; overflow-x: hidden; }
 #fhtpstugap .gt_stub { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; }
 #fhtpstugap .gt_indent_1 { text-indent: 5px; }
 #fhtpstugap .gt_indent_2 { text-indent: calc(5px * 2); }
 #fhtpstugap .gt_indent_3 { text-indent: calc(5px * 3); }
 #fhtpstugap .gt_indent_4 { text-indent: calc(5px * 4); }
 #fhtpstugap .gt_indent_5 { text-indent: calc(5px * 5); }
 #fhtpstugap .gt_stub_row_group { color: #333333; background-color: #FFFFFF; font-size: 100%; font-weight: initial; text-transform: inherit; border-right-style: solid; border-right-width: 2px; border-right-color: #D3D3D3; padding-left: 5px; padding-right: 5px; vertical-align: top; }
 #fhtpstugap .gt_row_group_first td { border-top-width: 2px; }
 #fhtpstugap .gt_row_group_first th { border-top-width: 2px; }
 #fhtpstugap .gt_striped { color: #333333; background-color: #F4F4F4; }
 #fhtpstugap .gt_table_body { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fhtpstugap .gt_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fhtpstugap .gt_first_summary_row { border-top-style: solid; border-top-width: 2px; border-top-color: #D3D3D3; }
 #fhtpstugap .gt_last_summary_row_top { border-bottom-style: solid; border-bottom-width: 2px; border-bottom-color: #D3D3D3; }
 #fhtpstugap .gt_grand_summary_row { color: #333333; background-color: #FFFFFF; text-transform: inherit; padding-top: 8px; padding-bottom: 8px; padding-left: 5px; padding-right: 5px; }
 #fhtpstugap .gt_first_grand_summary_row_bottom { border-top-style: double; border-top-width: 6px; border-top-color: #D3D3D3; }
 #fhtpstugap .gt_last_grand_summary_row_top { border-bottom-style: double; border-bottom-width: 6px; border-bottom-color: #D3D3D3; }
 #fhtpstugap .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fhtpstugap .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fhtpstugap .gt_left { text-align: left; }
 #fhtpstugap .gt_center { text-align: center; }
 #fhtpstugap .gt_right { text-align: right; font-variant-numeric: tabular-nums; }
 #fhtpstugap .gt_font_normal { font-weight: normal; }
 #fhtpstugap .gt_font_bold { font-weight: bold; }
 #fhtpstugap .gt_font_italic { font-style: italic; }
 #fhtpstugap .gt_super { font-size: 65%; }
 #fhtpstugap .gt_footnotes { color: font-color(#FFFFFF); background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fhtpstugap .gt_footnote { margin: 0px; font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; }
 #fhtpstugap .gt_sourcenotes { color: #333333; background-color: #FFFFFF; border-bottom-style: none; border-bottom-width: 2px; border-bottom-color: #D3D3D3; border-left-style: none; border-left-width: 2px; border-left-color: #D3D3D3; border-right-style: none; border-right-width: 2px; border-right-color: #D3D3D3; }
 #fhtpstugap .gt_sourcenote { font-size: 90%; padding-top: 4px; padding-bottom: 4px; padding-left: 5px; padding-right: 5px; text-align: left; }
 #fhtpstugap .gt_footnote_marks { font-size: 75%; vertical-align: 0.4em; position: initial; }
 #fhtpstugap .gt_asterisk { font-size: 100%; vertical-align: 0; }
 
</style>

<table class="gt_table" aria-labelledby="title" aria-describedby="subtitle" data-quarto-disable-processing="false" data-quarto-bootstrap="false">
<thead>
<tr class="gt_heading">
<th colspan="3" id="title" class="gt_heading gt_title gt_font_normal">Target encoding of the 300 makes</th>
</tr>
<tr class="gt_heading">
<th colspan="3" id="subtitle" class="gt_heading gt_subtitle gt_font_normal gt_bottom_border">Second-stage GLM by credibility constant K</th>
</tr>
<tr class="gt_col_headings">
<th class="gt_col_heading gt_columns_bottom_border gt_left" scope="col"></th>
<th id="cv-pseudo-R2" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">cv pseudo-R2</th>
<th id="coefficient" class="gt_col_heading gt_columns_bottom_border gt_right" scope="col">coefficient</th>
</tr>
</thead>
<tbody class="gt_table_body">
<tr>
<th id="stub-1" class="gt_row gt_left gt_stub" scope="row">16</th>
<td class="gt_row gt_right" headers="stub-1 cv-pseudo-R2">0.040</td>
<td class="gt_row gt_right" headers="stub-1 coefficient">0.82</td>
</tr>
<tr>
<th id="stub-2" class="gt_row gt_left gt_stub" scope="row">64</th>
<td class="gt_row gt_right" headers="stub-2 cv-pseudo-R2">0.041</td>
<td class="gt_row gt_right" headers="stub-2 coefficient">1.08</td>
</tr>
<tr>
<th id="stub-3" class="gt_row gt_left gt_stub" scope="row">256</th>
<td class="gt_row gt_right" headers="stub-3 cv-pseudo-R2">0.039</td>
<td class="gt_row gt_right" headers="stub-3 coefficient">1.41</td>
</tr>
<tr>
<th id="stub-4" class="gt_row gt_left gt_stub" scope="row">1024</th>
<td class="gt_row gt_right" headers="stub-4 cv-pseudo-R2">0.037</td>
<td class="gt_row gt_right" headers="stub-4 coefficient">2.24</td>
</tr>
<tr>
<th id="stub-5" class="gt_row gt_left gt_stub" scope="row">4096</th>
<td class="gt_row gt_right" headers="stub-5 cv-pseudo-R2">0.035</td>
<td class="gt_row gt_right" headers="stub-5 coefficient">4.98</td>
</tr>
</tbody>
</table>


The baseline GLM scored 0.021 without make; the encoded make roughly doubles that. As in Figure 6.1, the score is flat over a wide range of `K`, best near 64. As in Figure 6.2, the coefficient rises with `K`: a heavily shrunk encoding needs a coefficient above 1 to restore the spread. The best score and a coefficient near 1 occur at the same `K`, as section 6.6 expects when the encoding is correct. The rest of the guide uses `K` = 64.

A generalized linear mixed model (section 6.5) treats make as a random effect and shrinks it the same way. Section 6.8.2 gives the Bayesian view of ridge, which is [BayesGlm](../reference/models.BayesGlm.md#prospicio.models.BayesGlm) with normal priors.


# 5. The printed numbers of chapters 3 to 6 and prospicio's

| Where | Printed | Recomputed | Note |
|----|----|----|----|
| Table 3.1 pseudo-R2 | 47% | 0.471 | matches |
| Section 3.5 linear predictor | -2.467, 0.085 | -2.467, 0.085 | matches |
| Section 3.7.4 rebasing | 1.0031 | 1.0031 | matches |
| Section 4.1 variance | 0.09, 0.30 | 0.09, 0.30 | matches |
| Section 4.7.2 ridge in cm | 0.019, 1.9 | 0.019998, 1.9998 | printed digits truncated |
| Section 5.2 one step | 0.00509, 0.2302 | 0.00508, 0.2302 | relativity matches, the frequency is 0.005082 |
| Section 5.2 three steps | 0.00783 to 0.00119 | 0.00799 to 0.00122 | all about 2% higher, which points at the printed intercept |
| Table 5.7 cumulative | 2.06 | 2.067 | Table 5.8 prints 2.07 |
| Section 6.6 K | 648, 0.61 | 648, 0.61 | matches |
| Table 6.5 encodings | 0.079, 0.363, 3.266, 3.579 | 0.079, 0.363, 3.264, 3.580 | Marlin from its printed [z](../reference/reserving.CalendarYearTest.md#prospicio.reserving.CalendarYearTest.z), exposures printed rounded, 222.22 in the text is 223.75 |

Next: [part 2](glm-to-comprehensive-pricing-chalk-2.md), chapters 7 to 10.
