Pricing
Stop 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.
A tariff starts with its encoding
In a pet insurance engagement, breed clearly drove the risk, but 74 breeds were too many levels for a stable tariff. Grouping them by risk, meant only to make the tariff readable, showed nine breeds paying out 107% of their premiums in claims: they were priced below their cost. The variable had been in the data all along; what was missing was an encoding that let the model see it.
A GLM, a GAM or a gradient-boosting model can only learn what its variables let it see. A continuous variable such as age is cut into classes or kept as a curve; a category with many values is grouped or left raw. This step is often settled in a few minutes, by habit, and it decides a large part of the result: too many raw levels and the model learns noise, too few or badly placed classes and it misses the risk.
Four ways to get it wrong, measured
Each usual encoding has its own failure:
- Fixed-width bands, ages by five or ten years: blind to the risk. A boundary falls in the middle of a level, ages that behave alike are split, ages that differ share a coefficient.
- Quantile bins, classes of equal exposure: balanced in volume, still blind to the risk. The boundaries fall where the policies are, not where the risk changes.
- Every raw value its own class: the thinnest values receive coefficients built on a handful of claims.
- Classes chosen on the data that built them: more classes nearly always fit the training data better, so a choice made on those data goes to the largest number on offer, or close to it.
We measured all four on a world whose truth is known: ages 18 to 79, a claim frequency in three steps, 0.05 up to 35, 0.10 up to 60 and 0.20 above; 6,000 policies of one to three yearly rows, and an independent test portfolio of the same size; 30 portfolios. Every class rate is learned on the training portfolio. The score is the share of the achievable gain reached on the test policies, from 0% for a single average frequency to 100% for the true frequencies.
- Our engine found three classes in 26 portfolios out of 30, with boundaries at most three years from 35 and 60 (exactly at 35 and 60 in 14), and two classes in the other four: 97% of the achievable gain in median.
- The best fit on the training data, among the very same exact partitions as our engine, took the largest number offered, six classes, in 29 portfolios out of 30, and five in the other: 93% in median. None of its classes was priced at zero: the precision rule of step 2 refuses a class with no claim and little exposure.
- Fixed bands and quantiles: 87% for 5-year bands (13 classes), 86% for 10-year bands (7), 80% for five classes of equal exposure. Raw ages: 72% with 62 classes.
The world without any effect is the harder test: a frequency of 0.10 at every age. Several classes are not a fault in themselves: fixed bands, quantiles and raw values create them by construction, whatever the data, and the best training fit always found some, in all 30 portfolios. What matters is whether the differences between classes reflect a credible effect, whether they bring a gain on new policies, and whether they make prices differ without reason. Here there is no effect to find: every difference in price between classes is unjustified and adds noise to every premium. On new policies, none of the usual encodings gained anything: on average each made the test deviance worse than a single average, from 0.06% for five classes of equal exposure to 1.7% for raw ages. Our engine returned a single class in all 30 portfolios, no split where there is none; with 30 portfolios, the 95% interval of that rate still runs from 0% to 11%; a single class is its way of saying that it found nothing to price.
Step 1: the risk is a ratio of sums
Our engine runs in five steps, in this order. The risk of a class is its total claims, cost or charge divided by its total exposure or premium, never an average of individual ratios, which unequal exposures would bias. With the claims, cost or charge of row , its exposure or premium and its value of the variable, the rate of a class of values is:
Up to three measures can be used together, claim frequency, pure premium, loss ratio, each with its own loss family declared by the analyst: Poisson for a count, Tweedie with its power for an amount, Gaussian otherwise. A measure can take the expected value of a current model as denominator: the risk then becomes observed against expected, the effect of the variable once the other rating factors are accounted for. A row whose denominator is zero, negative or missing enters no rate and is counted; missing values form their own class.
Step 2: a class must be precise enough to exist
Before any partition is built, every candidate class is tested. Its standard error is computed per independent unit, the policy or the insured, never per row, since the rows of one policy are not independent. For a class on measure , with and the totals of unit within the class:
The scale is the overall rate of the measure for a count or an amount, and for a Gaussian measure the dispersion of the value rates, computed for every measure, , with and the denominator and the rate of value and the total denominator; all are learned on the training rows. The ceiling is declared before the data are seen, 0.15 by default. The error measured unit by unit vanishes for a class without any claim, or with a single unit, so it is bounded below by a floor that does not depend on the claims of the class: is the variance within cells per unit of denominator, the expected process variance of formula (6) below computed on cells instead of values, learned on the training rows; each cell holds at least two units, the values themselves for a category, the shortest runs of neighbouring values for an ordered variable. For a claim count without overdispersion, is close to the overall frequency, and the ceiling then asks for about 44 expected claims at that frequency: a relative standard error of 15%, a margin of about ±30% at 95% under the normal approximation, a tolerance we declare, not a universal standard. A class with no claim and little exposure is therefore refused; a class with no claim but a large exposure, whose low rate is measured precisely, passes. When the floor cannot be estimated, for lack of enough units sharing a cell (a minimum declared in advance), the engine forms no classes and names the reason: a refusal of this procedure, which says nothing about the risk the variable carries; the variable stays in the analysis, to be modelled another way. Precision is not predictive power: the number of classes is still chosen out of sample, in step 4. There is no threshold in number of rows: a hundred rows of small exposure can weigh less than thirty heavily exposed ones. A class that fails on any measure is excluded from every candidate partition with two classes or more; the single class of the whole portfolio always stays allowed, as the reference.
Step 3: the best partition for each number of classes
For a given number of classes, the best partition minimises the dispersion of risk within the classes, weighted by exposure; since total dispersion is exactly within plus between, the same partition maximises the separation between classes. For an ordered variable, only neighbouring values may be grouped, so that 5 years never ends up with 75 years, and the best contiguous partition is found exactly by dynamic programming, a weighted form of Fisher’s algorithm, where k-means would only reach a local optimum. With the values in order, is the smallest within-class cost of the first values cut into classes, the cost of the class made of values to , set to infinity when that class fails rule (2), and its rate on measure :
Each class cost is obtained in constant time from cumulative sums. The weight makes each measure count by its share of variance, not by the unit of its denominator: exposure in years and premiums in currency must not decide the result. With the weight declared for measure :
A breed or a product has no order, and its small values are noisy: twelve policies without a claim do not mean a zero risk. Each value is first credibility-weighted (Bühlmann-Straub), pulled toward the overall rate as much as its exposure is small:
The two variances are estimated on the training rows, the units inside each value serving as its replications. With and the totals of unit at value , , the number of units with a positive denominator at value , the number of values and :
When the between-value variance is zero on every measure, there is a single class, never an arbitrary cut. With one measure, the credibility-weighted values are then cut by programme (3), with in place of , exactly among the partitions contiguous in the order of their risk. With several, they are grouped by Ward’s agglomeration, each measure with its own weights and the classes that fail rule (2) merged first, then refined by Lloyd iterations under the same cost; the refinement is kept only when it settles on classes that all pass rule (2).
Step 4: the number of classes, chosen out of sample
This is where the method learns from the data without flattering itself. More classes always lower the within-class cost, so that cost cannot choose their number. The choice is made on rows the grouping has not seen. The rows are split into folds (five by default), each unit whole on one side: unit goes to fold , with a random permutation of the units drawn from a declared seed. When time matters, the past is used to predict the future instead: with the date of row , the quantile of order of the dates and the units that have a row in the held-out block, for ,
so that no unit of the held-out block is seen in training. In each fold, everything is learned on the training rows alone: the scales, the weights (4), the credibility (5) and (6), the support (2) and the partitions (3) for every number of classes up to a declared maximum (six by default). The held-out rows only judge. Each row is predicted , the training rate of its class times its denominator (a value unseen in training takes the class of the nearest learned value below it, the first class when it lies below all of them, or the overall rate for a category), and the deviance of the claims measures the error; for a count, with the term set to zero when :
An amount uses the Tweedie deviance with its declared power, a Gaussian measure the exposure-weighted squared error. With the mean of over the folds, the number with the best mean gain, and the standard error of the paired differences over the folds, the number kept is the smallest one close enough to the best:
Only numbers feasible in every fold compete. When a single class is chosen while a larger number, feasible on all the rows, could not be judged in every fold, the result says so by name instead of passing for an ordinary single class. If the number chosen is not feasible on all the rows, the same rule chooses again among the smaller feasible numbers, and the change is reported. The one-standard-error rule of Hastie, Tibshirani and Friedman inspired it; we declare , because on simulated worlds with no effect at all it gave false groups in 0% of 30 worlds for categories and 3% for an ordered variable, against 3% and 10% with one standard error, while planted steps were still found. Apart from those named cases, one class is a normal answer: no out-of-sample gain was detected for the variable. These settings are declared in a configuration file with their provenance, before any data are seen; the engine stops, naming what is missing, rather than fill one in.
Step 5: two outputs, frozen classes and a cross-fitted relativity
The partition with the chosen number of classes is then fitted on all the rows with a value and frozen: these are the classes of a readable tariff, each with its members, its rate, its per-unit standard error and a band, the Garwood interval, exact under the Poisson assumption, for a whole count of claims, a bootstrap over units for an amount, labelled descriptive because its coverage is not verified. Training a model on those classes, on the same rows, would flatter it: each row would have helped draw the class that then predicts it. The second output removes that circularity. For each fold , the whole procedure, the choice of included, is run again without it (with time, on the earlier blocks, held-out units purged), and each row , in fold , receives the rate of its class learned without that fold, relative to the overall rate learned without it; a missing value receives the rate of the training rows with a missing value:
It is a difference rather than a ratio for a Gaussian measure; when time matters, the first period has no past to learn from and receives none. This relativity is the signal to train a GLM or a gradient-boosting model on; the frozen classes go into the tariff, to be validated on later years. The engine also reports how close each fold’s classes are to the final ones (mean adjusted Rand index), and the gain of every number of classes, fold by fold. The two figures below are its own drawings on simulated portfolios, with only their labels put into words: an ordered variable as steps with their bands, and categories on a map of pure premium against loss ratio, each class with an ellipse that plays the part of a box plot in two dimensions; with a third measure the map turns 3D, with one ellipsoid per class.
Measured on new policies: what the encoding changes for the GLM
We measured it. Thirty simulated portfolios of 20,000 policies, each with an independent test portfolio of the same size; a Poisson GLM with a second rating factor; the score is the share of the achievable gain reached on the test policies, from 0% for a single average frequency, with no rating variable at all, to 100% for the true frequencies.
- Breeds. 74 breeds left raw (75 coefficients in all) make the model worse than ignoring the breed, at −30% on average (median −18%): small breeds receive extreme coefficients that do not hold on new policies. Grouped by risk, three classes in median, the same variable reaches 69%, better than the raw breeds in 28 portfolios out of 30.
- Age, with a smooth effect. A straight line misses the curve (32%) and 62 raw values overfit (35%). Grouping by risk reaches 61% with two classes in median. On this smooth curve and at this size, 5-year bands do better (79%): the rule that protects against false classes stays cautious when each extra class brings little. On 150,000 policies (ten portfolios) the gap narrows to a few points, 91% against 94%, with six classes instead of thirteen.
The lesson is simple. With the same model and the same data, the encoding alone takes the breed from −30% to 69%. The largest gains are on categories with many values, where raw coefficients fail most. For a smooth ordered variable, well-chosen bands remain a fair baseline; what the method adds is that the classes and their number come from the data, with a measured control against classes that do not exist. All these comparisons are against the usual encodings; a competent smoothing method, such as a spline in a GAM, was not measured against our engine.
What the engine refuses, reports, and does not do
- It refuses to guess. Without the independent unit, or without the loss family of each measure, it stops with a named message; no silent default stands in for either.
- It reports instead of hiding. One class is returned as a result, not as a failure, and with a named reason when it comes from a refusal rather than from the data: a precision floor that cannot be estimated, or validation folds too thin for a larger number; a measure with no dispersion, a zero overall rate or no denominator is retired and named; the rows left out for a zero, negative or missing denominator are counted; the gains of every number of classes are given fold by fold, and the stability of the classes as one mean adjusted Rand index.
- It does not impose monotonicity. For an ordered variable the classes are contiguous, but their rates are free to rise and fall: if the risk is U-shaped, the classes say so.
- Its limits are stated. With several measures on categories, Ward’s grouping is deterministic but not guaranteed optimal. It groups one variable at a time; for several, the expected value of a model as denominator isolates what each one adds. On a smooth effect and a small portfolio, well-chosen fixed bands can do better, as measured above, because the rule that guards against false classes stays cautious when each extra class brings little.
What it changes for a tariff
Classes that follow the risk instead of the calendar, fewer coefficients where the data are thin and more where they are rich, groups of categories that can be explained to an underwriter, and a number of classes that can be defended in front of a reviewer, because it was chosen on data the method had not seen. Every setting is declared, and the whole run can be replayed and audited.
References
W. D. Fisher (1958), “On grouping for maximum homogeneity”, Journal of the American Statistical Association; H. Bühlmann and E. Straub (1970), “Glaubwürdigkeit für Schadensätze”, Mitteilungen der Vereinigung Schweizerischer Versicherungsmathematiker; J. H. Ward (1963), “Hierarchical grouping to optimize an objective function”, Journal of the American Statistical Association; S. P. Lloyd (1982), “Least squares quantization in PCM”, IEEE Transactions on Information Theory; T. Hastie, R. Tibshirani and J. Friedman (2009), The Elements of Statistical Learning, 2nd ed., Springer, section 7.10 (the one-standard-error rule, used here with two standard errors of paired differences); F. Garwood (1936), “Fiducial limits for the Poisson distribution”, Biometrika; L. Hubert and P. Arabie (1985), “Comparing partitions”, Journal of Classification.
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 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 articleActuarial modellingClustering high-cardinality categories before a pricing GLM
74 breeds, too many for a stable tariff: making categories comparable with target-oriented K-means instead of dropping them, validated out of sample and in the GLM.
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


