Actuarial workflow
Azoic follows one explicit path: understand the portfolio, preserve a final holdout, fit candidates under the same exposure convention, and judge ranking, calibration, and business plausibility together.
The sequence
- Declare record IDs, predictor columns, units and claim valuation assumptions.
- Reserve the final-test portfolio and save its membership before profiling or experimentation. Use a predeclared time cutoff when appropriate.
- Check development data, then profile its predictors and decide what to keep, bin, group or drop.
- Select preprocessing and model parameters only inside development training data.
- Refit the selected candidates on outer training data, measure training O/P for every candidate, and freeze any training-derived level adjustment before inspecting development validation. Evaluate raw and adjusted candidates on the same development validation rows.
- Review diagnostics and relativities before reporting or exporting a tariff.
Leakage boundary
A final test result is evidence only if outcomes, preprocessing decisions,
and tuning trials did not influence that partition. Supply only development
data to run_experiment and tune_experiment. Their test fields mean
development validation: repeated candidate comparisons can influence selection.
Tuning uses an inner split of development training data. Final-test evaluation
of a frozen fit is a separate saved-artifact operation.
Pure-premium weighting
For a rate response, use
\(y_i = \text{claim amount}_i / \text{exposure}_i\) with exposure as
sample_weight. Use a log-exposure offset only for an aggregate claim
amount response. Never combine the two formulations.
The special columns travel inside X so scikit-learn pipelines and
GridSearchCV can route them. Estimators remove those columns before fitting
features.
Freeze portfolio membership before experimenting
This section requires Azoic 0.6.0. It follows the synthetic
first model, which creates portfolio.parquet.
For your own portfolio, use an existing durable record ID and a documented
cutoff or an externally chosen ID list independent of claims. The synthetic IDs
below are assigned once; never regenerate them after sorting or filtering.
The numbered periods here are synthetic labels, not calendar dates.
import json
import pandas as pd
from azoic import DatasetSpec, ExperimentConfig, ModelSpec, check_experiment, split_portfolio
portfolio = pd.read_parquet("portfolio.parquet")
portfolio["record_id"] = [f"policy-{i}" for i in range(len(portfolio))]
portfolio["partition"] = "development"
# Reserve the last four synthetic periods before any development decisions.
final_ids = portfolio.loc[portfolio["period"] >= 20, "record_id"].tolist()
portfolio.loc[portfolio["record_id"].isin(final_ids), "partition"] = "final-test"
development, final_test = split_portfolio(portfolio, final_ids, id_col="record_id")
# Run once into a fresh directory; keep these files fixed during experimentation.
with open("portfolio-membership.json", "x", encoding="utf-8") as stream:
json.dump({"development": development["record_id"].tolist(),
"final_test": final_test["record_id"].tolist()}, stream, indent=2)
development.to_parquet("development.parquet", index=False)
final_test.to_parquet("final-test.parquet", index=False)
config = ExperimentConfig(
name="development-candidates",
data_path="development.parquet",
spec=DatasetSpec(
target="claim_amount", exposure="exposure", claim_count="claim_count",
time_col="period", id_col="record_id", excluded_cols=["partition"],
exposure_unit="year", currency="EUR",
observation_period="synthetic periods 0–19",
claim_valuation_basis="synthetic simulated ultimate amounts",
adjustments=["no external caps or adjustments"],
),
features=["driver_age", "vehicle_age", "region"],
split="temporal",
models={"glm": ModelSpec(params={"family": "tweedie", "link": "log"})},
)
print(check_experiment(config))
Keep final-test.parquet closed throughout selection; pass df=development
or point data_path at development.parquet for fitting and tuning. Save the
membership file before running the check or exploring predictors. The helper
preserves source row order and index labels, returns separate copies, rejects
missing/duplicate/unknown IDs and empty partitions, and removes unused category
levels separately. It does not validate final-test outcomes or change row values.
Returned DataFrames are mutable: the helper does not enforce file access control
or prevent a caller from later supplying the wrong portfolio.
id_col and excluded_cols never enter model fitting. Add incumbent technical
rates and other partition metadata to excluded_cols when present. Names alone
cannot identify leakage: explicitly list predictors and review them for IDs,
incumbent rates and information unavailable at the pricing date. Excluded columns
remain required in the declared training data, but not in prediction frames.
Run.record_ids records the supplied development row IDs; train_indices and
test_indices address that tuple in fit/validation order.
Exposure is measured in years; other units must be converted upstream. Currency,
observation period, claim valuation basis and adjustments record your declared
assumptions in the config and model card. They do not apply inflation, claims
development, caps or data repair. Unspecified assumptions remain unrecorded.
check_experiment and azoic check --config development.yaml require a nonempty
explicit predictor list. They check existing portfolio, column-role and split
rules, GBM parameters and estimator/preprocessor construction without fitting or
writing. When tuning is declared, the check also validates tree-count search
spaces and applies the configured split to the outer training rows.
Backend convergence, predictor validation and learned mapping behavior
still require fitting. See the preflight checks.
Read each diagnostic for its own question
Ranking
The concentration Gini orders policies from safest to riskiest by predicted pure premium. Equal scores are aggregated before integration, so row order inside a tied score cannot change the result. Positive Gini means observed claims concentrate in the high-predicted-risk tail.
Write \(u\) for cumulative exposure share and \(C(u)\) for cumulative claim share in prediction order. Azoic computes
This is twice the signed area from the concentration curve to the diagonal, so it may be negative. A positive Gini does not require the curve to stay below the diagonal everywhere, and zero Gini does not prove random ranking. Strictly increasing transformations that preserve ties, including positive scaling, leave it unchanged and therefore cannot establish premium level.
The pairwise absolute-difference inequality Gini measures observed-rate dispersion independently of model predictions. With rates \(r_i\) and exposures \(w_i\), it is
It equals concentration Gini when ranking by observed rates. Azoic integrates tied-score blocks, equivalently the midrank formula; it does not compute pairwise differences. Its hindsight upper bound generally falls below one. For rates \([1,3]\) and exposures \([1,2]\), the observed-rate curve passes through \((1/3,1/7)\), its area is \(17/42\), and Gini is \(4/21\). Reversing the prediction ordering gives \(-4/21\), while inequality stays \(4/21\). The tutorial executes this example.
Distributional accuracy
Exposure-weighted deviance is a proper score for the assumed response family. Smaller is better when models use the same response, holdout, and family. Compare Poisson with Poisson, Gamma with Gamma, and Tweedie with the same Tweedie power.
Explained deviance is
Higher is better, but \(D^2\) values from different response families are not comparable.
Portfolio and segment calibration
The observed/predicted ratio is
An O/P ratio near 1 is necessary, not sufficient. Opposing segment biases can cancel at portfolio level, so inspect calibration and one-way tables as well.
Measure training O/P for every GLM and GBM candidate. Poisson, Gamma, and Tweedie losses target conditional means; they do not inherently target below the mean. Restrictions on the model, regularization, finite boosting iterations, and solver convergence affect achieved calibration. A GLM intercept or a Poisson GBM objective alone is not a guarantee of total balance.
For observed rate \(r\), predicted rate \(\mu\), and exposure \(w\), our chain-rule derivation from glum's deviance and log-link definitions gives the converged, unpenalized log-link GLM intercept equation
For Poisson (\(p=1\)), it implies training total balance. For Gamma (\(p=2\)) and Tweedie (\(1<p<2\)), it generally does not. All three intercept-only fits recover the weighted mean; adding a varying feature can break total balance for Gamma and Tweedie even with a converged intercept score. None of these statements guarantees held-out calibration or balance of a frequency–severity product. The tutorial includes fitted counterexamples and a Poisson control with solver tolerances.
If choosing an explicit burn-cost adjustment, calculate each factor as \(c_m=\sum_{\mathrm{train}}\mathrm{claim\ amount}/\sum_{\mathrm{train}}w\mu_m\) on the stored training rows and freeze it before inspecting test outcomes. Multiplying by \(c_m\) balances training totals. It need not improve test deviance, test O/P, or segment calibration. Show labelled raw and adjusted holdout results on the same positions; state which predictions feed charts, scoring, and distillation. The tutorial labels its adjusted comparison charts and scoring separately from the raw GLM structure illustrations. Its distillation teacher and run reports stay raw.
Visual evidence
| View | Question | Useful signal | Boundary |
|---|---|---|---|
| Lorenz curve | Does the model rank risk? | A curve below the diagonal and non-crossing dominance over a benchmark | Crossing curves do not establish one winner |
| Lift chart | Does observed risk rise with predicted decile, and do levels agree? | Increasing observed lift with observed and predicted lines close together | Wide gaps are calibration errors, not ranking errors |
| Calibration chart | Are segment predictions on level? | Exposure-heavy points near the diagonal | It says nothing about individual-policy accuracy |
| One-way chart | Is a feature segment systematically mispriced? | Observed and predicted lines track across credible levels | Thin-exposure levels are noisy |
| Double-lift chart | Which prediction matches observations within each ratio group? | Smaller observed-minus-predicted gaps in credible groups | Rising observations alone cannot select a model; inspect extreme disagreements |
| Actual vs predicted | Where is policy-level density and residual structure? | Credible grouped mean residuals near zero | The densest band need not be the conditional mean |
In a double-lift view, observed and B rates \([10,20,30]\) against A rates \([1,20,90]\) give rising A/B ratios, yet B matches all three groups. The CAS GLM monograph, section 7.2.2, pp. 78–79 compares predictions with observations within ratio groups using normalized curves. Azoic shows absolute rates, retaining level differences. Extreme ratio groups contain the largest relative disagreements; assess their exposure and claims credibility rather than assuming the middle is most informative.
Residuals are \(e=r-\mu\). A constant non-zero conditional mean residual indicates an additive discrepancy: \(r=\mu+5\) gives \(e=5\), which one multiplier cannot generally remove. If \(r=c\mu\), then \(e=(c-1)\mu\); this slope is entirely multiplicative and one factor can remove it. Inspect credible exposure-weighted grouped means before attributing remaining curvature to missing structure. Claim-free policies create residuals near \(-\mu\), so the densest band is not necessarily the mean.
The diagnostics and visualization guide contains the runnable table and plotting recipes.
Five checks before choosing a model
- Accuracy. Held-out deviance beats a within-family benchmark and \(D^2\) improves.
- Portfolio calibration. O/P is credible, and one-way views do not reveal material offsetting bias.
- Ranking. Gini is positive and the Lorenz curve improves without relying on calibration claims.
- Lift. Observed risk generally rises with predicted risk while observed and predicted levels remain close.
- Business review. Relativities are plausible, fairness and governance checks pass, and the result is stable enough for its decision.
No single metric makes a pricing decision. The conclusion comes from agreement between distributional accuracy, ranking, calibration, stability, and business constraints.
Profile and preprocess data Compare model families Look up a term Open the complete tutorial