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.

Category profiles and the three K-means groups
Category profiles and the three K-means groups

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.

Elbow and silhouette agree on three groups
Elbow and silhouette agree on three groups

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.

Distributions by group and the ANOVA test
Distributions by group and the ANOVA test

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.

Raphael Sebbah

About the author

Raphael Sebbah

Actuary (ISUP) and data scientist, founder of Smart Data Science. Formerly at Amundi (CAAM), Dexia, AIG and Phoenix; co-author of research published in The European Physical Journal C and Brain Communications.

LinkedIn · ORCID · Google Scholar

Let’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