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:

  1. 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.
  2. 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.
  3. Every raw value its own class: the thinnest values receive coefficients built on a handful of claims.
  4. 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.

  1. 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.
  2. 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.
  3. 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.

Four usual encodings against our engine, on a known three-step truth and on a world with no effect
Four usual encodings against our engine, on a known three-step truth and on a world with no effect

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 Ni the claims, cost or charge of row i, Ei its exposure or premium and xi its value of the variable, the rate of a class g of values is:

mg=∑i:xi∈gNi∑i:xi∈gEi(1)

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 g on measure d, with Nu,d and Eu,d the totals of unit u within the class:

se(mg,d)2=max(∑u(Nu,d−mg,dEu,d)2(∑uEu,d)2, Vd∑uEu,d)se(mg,d)σd≤ρ
(2)

The scale σd is the overall rate m¯d of the measure for a count or an amount, and for a Gaussian measure the dispersion sd of the value rates, computed for every measure, sd2=1Wd∑xwx,d(mx,d−m¯d)2, with wx,d and mx,d the denominator and the rate of value x and Wd 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: Vd 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, Vd 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, Φ(k,j) is the smallest within-class cost of the first j values cut into k classes, C(h,j) the cost of the class made of values h to j, set to infinity when that class fails rule (2), and mhj,d its rate on measure d:

Φ(1,j)=C(1,j)Φ(k,j)=mink≤h≤j[Φ(k−1,h−1)+C(h,j)]C(h,j)=∑dcd∑x=hjwx,d(mx,d−mhj,d)2
(3)

Each class cost is obtained in constant time from cumulative sums. The weight cd 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 ad the weight declared for measure d:

cd=adsd2Wd(4)

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 m¯ as much as its exposure wx is small:

m~x=Zxmx+(1−Zx)m¯Zx=wxwx+EPV/VHM
(5)

The two variances are estimated on the training rows, the units inside each value serving as its replications. With Nu,x and Eu,x the totals of unit u at value x, yu,x=Nu,x/Eu,x, nx the number of units with a positive denominator at value x, R the number of values and W=∑xwx:

EPV=∑x∑uEu,x(yu,x−mx)2∑x(nx−1)VHM=max(0,∑xwx(mx−m¯)2−(R−1)EPVW−∑xwx2/W)
(6)

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 m~x in place of mx, 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).

Age grouped by risk: the classes found from the data
Age grouped by risk: the classes found from the data
Breeds grouped by risk, pure premium against loss ratio
Breeds grouped by risk, pure premium against loss ratio

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 F folds (five by default), each unit whole on one side: unit u goes to fold π(u)modF, 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 ti the date of row i, qf the quantile of order f/(F+1) of the dates and Uf the units that have a row in the held-out block, for f=1,…,F,

Vf={i∣qf<ti≤qf+1}Tf={i∣ti≤qf, ui∉Uf}
(7)

so that no unit of the held-out block is seen in training. In each fold, everything is learned on the training rows Tf alone: the scales, the weights (4), the credibility (5) and (6), the support (2) and the partitions (3) for every number of classes K up to a declared maximum (six by default). The held-out rows Vf only judge. Each row i is predicted μi,d=m^gK(xi),dEi,d, 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 Nln(N/μ) set to zero when N=0:

Dd(f)(K)=2∑i∈Vf[Ni,dlnNi,dμi,d−(Ni,d−μi,d)]G(f)(K)=∑dadGd(f)(K)∑dadGd(f)(K)=Dd(f)(1)−Dd(f)(K)Dd(f)(1)
(8)

An amount uses the Tweedie deviance with its declared power, a Gaussian measure the exposure-weighted squared error. With G¯(K) the mean of G(f)(K) over the folds, K⋆ the number with the best mean gain, and SE(K) the standard error of the paired differences G(f)(K⋆)−G(f)(K) over the folds, the number kept is the smallest one close enough to the best:

K^=min{K∣G¯(K)≥G¯(K⋆)−λSE(K)}(9)

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 λ=2, 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 f, the whole procedure, the choice of K included, is run again without it (with time, on the earlier blocks, held-out units purged), and each row i, in fold f(i), 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:

ri=mg(−f(i))(i)(−f(i))m¯(−f(i))(10)

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.

Categories by pure premium and loss ratio, one ellipse per class, as drawn by our tool (simulated portfolio)
Categories by pure premium and loss ratio, one ellipse per class, as drawn by our tool (simulated portfolio)
Age cut into contiguous classes, as drawn by our tool (simulated portfolio)
Age cut into contiguous classes, as drawn by our tool (simulated portfolio)

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.

  1. 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.
  2. 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.

Share of the achievable gain reached on new policies, by encoding
Share of the achievable gain reached on new policies, by encoding

What the engine refuses, reports, and does not do

  1. 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.
  2. 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.
  3. 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.
  4. 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.

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