Actuarial modelling
Clustering high-cardinality categories before a pricing GLM
74 breeds were too many levels for a stable pet-insurance tariff. Dropping the variable was the easy answer. We made the breeds comparable instead, each summarised by its risk and grouped with those that behave alike, and let the GLM decide whether the groups help. They did: nine breeds turned out to be priced below their cost.
Too many levels, and the easy answer
Breed clearly drove the risk of the pet policies, but with 74 breeds many had too little exposure to support a coefficient of their own. The usual encodings do not help: an ordinal code imposes an order that does not exist, and one-hot encoding turns 74 breeds into 74 columns, with sparse design matrices, unstable coefficients and noisy p-values. Under time pressure such a variable is often dropped, even when it clearly carries risk. The same happens with vehicle brands, disease families or providers.
Dropping it would have hidden what the grouping found. Nine breeds, among them Great Danes, Dobermans and French Bulldogs, paid out 107% of their premiums over the period, against 49% for the portfolio; the details are in our pricing case study.
Making the categories comparable
The idea is to group levels that behave alike with respect to the target, not levels that look alike. Each category is first summarised by a small numerical profile, here its pure premium, which carries frequency and severity, and its loss ratio, which adds the commercial view. K-means itself is unsupervised, but its inputs are built from the target, so the procedure as a whole is target-guided and has to be validated like a supervised step: two brands belong together if, for pricing, they behave alike. The loss ratio also carries the current tariff, claims over premium: it mixes the intrinsic risk with today’s price level, which is useful to find categories priced below cost but is not a pure measure of risk.
Two practical rules come first. A category with 40 exposures and one with 4,000 are not equally reliable points: profiles are best shrunk towards the portfolio level in proportion to their credibility (Bühlmann–Straub) before clustering, and categories with too little exposure are handled separately. And because K-means uses Euclidean distance, the profile variables are standardised so that neither dominates. With more than two metrics, a PCA can compress them before clustering.
How many groups
K-means always reduces its inertia as groups are added, so their number has to be chosen. In this engagement the elbow of the inertia curve and the average silhouette both pointed to three groups. Since then, our grouping method no longer reads the number from a chart: the groups are learned on part of the policies, judged on the others, and the smallest number within two standard errors of the best is kept, a single group being a valid answer.
Validate before using
A grouping is not accepted because it looks right. Box plots by group should show compact groups at clearly different levels, and a one-way ANOVA, or a Kruskal–Wallis test when the distributions are skewed, tests whether the group means really differ, but only on data the grouping has not seen: on the data used to form them, the groups were built to differ, the p-value loses its usual meaning and the comparison is descriptive only.
The decisive test is downstream: put the grouped feature into the GLM and compare it with the specification without it. Are its coefficients significant, does the information criterion improve, is the model more readable and still stable? The grouping must be learned on the training data and the comparison made on an independent validation sample or a later period; a comparison on the same sample is descriptive only.
Beyond one portfolio
The same approach applies wherever a categorical feature has too many levels to enter a model directly but still carries signal: providers, merchants, suppliers, laboratories, product families.
More publications
PublicationsDid it work? Measuring the effect of a decision without fooling yourself
A campaign, a new deductible, a reminder letter: did it change the outcome? Comparing those who received it with those who did not answers a different question. This article shows how we estimate the effect of a decision on observational data, what each estimate assumes, why the usual estimator can fail when the decision is rolled out in waves, what we do when only a few units received it, and how we keep a study of many segments from finding effects that do not exist.
Read the articlePricingStop grouping ages in fives: let the risk draw the classes
Most tariffs still group age, seniority or vehicle power into round bands chosen by hand, and categories with many values, breeds or products, by intuition. The bands rarely fall where the risk changes. Measured on simulated portfolios with a known truth, this article shows where the usual encodings go wrong, then how our engine lets the data draw the classes: compact in risk, precise enough to carry a coefficient, and in a number chosen on data the method has not seen.
Read the articleInsurance pricingGLM, GAM or gradient boosting: choosing a pricing model an insurer can defend
Which pricing model an insurer can defend: GLM relativities, smooth GAM effects, boosting as an interaction detector, and how to compare them.
Read the articleLet’s build better decisions together
Tell us about the decision you need to make.
A few lines are enough: your sector, the data you have and what you want to improve. We reply personally with a first view of the approach.
- A few lines are enough
- NDA on request
- Code and documentation handed over


