Data quality

One column, several populations: finding the real anomalies without flagging a second population

A column of payments can hold two kinds of amount: most of them around 100 to 200, a handful around 3,000. Read as one population, every value of the second group looks extreme, and a usual detection flags the group as a block. It is not an error, it is a population. Our detector recognises it on its own, leaves it alone and keeps flagging what is genuinely unusual, including an extreme above the second group. Measured on simulated data, with the limit we state.

The problem: a second population is not an error

Take a column of payment amounts. Most payments lie between 100 and 200; a few, recorded under the same label, are around 3,000: another kind of payment, another product, another unit. Nothing is wrong with them. They belong to a different population that shares the column.

A usual detection reads the column as one population. It measures each value against the bulk, around 100, and against that yardstick every payment near 3,000 is far away: the whole second group is flagged, value by value. If the flagged values are then removed or capped, a real segment of the payments disappears from the analysis, and with it the cost it carries.

The question is therefore not only “which values are extreme?”, but “extreme with respect to which population?”.

What our detector does, in broad strokes

Our detector works in a fixed order, and deletes nothing:

  1. Stability first. On a series over time, it first looks for lasting changes of level: a change is proposed, tested and kept only if it is validated, and each regime is then read on its own, once the test has been calibrated on comparable series; until then, candidate changes are only reported as leads. On a column read as a whole, such as a column of amounts, it looks at the shape of the distribution instead.
  2. Populations recognised on their own. Nobody has to declare that the column holds two populations; the step needs at least 40 values by default. The detector finds by itself the compact groups of values set apart from the rest, and treats each one as a population.
  3. Anomalies inside each population. Within each population large enough to be read (40 values by default), values are measured with statistics that a few extreme points cannot move and, when the order of the rows has a meaning, against their neighbours in time. A smaller population, such as the group of 11 below, is not examined inside: only a value beyond an empty gap is scored against it. A value is judged against the population it belongs to, not against the whole column.
  4. An extreme beyond a population stays flagged. A value that belongs to no population, such as an isolated amount far above the second group, is judged against the populations and flagged when it is extreme for all of them.

The result is coded, not cleaned: each population found is described in a report, with its count, its median and its range, and a note suggests checking with the owner of the data how that group is recorded. The decision stays with someone who knows the business.

In formulas, points 2 and 4 are the rules of step 4 of our article on outliers, with the same letters. The values are read on a working scale, y=lnx when every value is positive and the raw value otherwise. Candidate groups come from a mixture of K normal laws fitted to the n values, whose number of components grows only while each new one lowers the Bayesian information criterion by at least a declared margin Δ:

BIC(K)=−2ℓ^K+(3K−1)lnn,dj=BIC(j−1)−BIC(j),K^=max{K≤Kmax:dj≥Δ for every 2≤j≤K}
(1)

where ℓ^K is the maximised log-likelihood of the mixture, 3K−1 its free parameters (K means, K variances and K−1 weights), dj the drop of the criterion when a j-th component is added, and Kmax a declared maximum. The mixture only proposes candidates. A group G is set apart from the other values G¯ only across an empty gap:

g(G)>0andg(G)≥zsmax(σ^G,σ^G¯),σ^=1.4826MAD
(2)

where g(G) is the smallest width of the empty interval between G and the nearest other value, zero if another value lies within the range of G, σ^ a robust standard deviation and zs a declared multiple. A group set apart in this way is a population of its own when it holds at least three values and is compact:

|G|≥3,sG≤0.25|med(G)−med(H1)|
(3)

where sG is its standard deviation on the working scale and H1 the dominant population. The bound 0.25 is a declared, provisional setting and the minimum of three values a policy choice: both are declared, not learned. A value that belongs to no population is scored against the populations only, never against itself, and flagged when it is extreme for every population h:

minh0.6745|y−med(h)|MAD(h)≥z0(4)

where med(h) and MAD(h) are the median and the median absolute deviation of population h, and z0 the declared threshold.

Our detector on the first simulated draw: the distribution of the amounts and the two populations it recognised (yellow bands)
Our detector on the first simulated draw: the distribution of the amounts and the two populations it recognised (yellow bands)

Measured: the same draws, read two ways

We simulated the case, with no client data: 300 amounts around 100, 3 intermediate amounts between 190 and 220, 11 amounts between 2,700 and 3,000 and one isolated amount of 7,000, drawn 5 times. Each draw was read twice by our detector with the same settings: once as it runs, populations recognised; once with that step switched off, the column read as a single population, as a usual detection reads it.

Read as one population, the second group was flagged as a block: all 11 of its values in each of the 5 draws, 55 out of 55. Read with its populations, the second group was recognised in 5 draws out of 5 and none of its 55 values was flagged, while the 7,000 above it was flagged in 5 draws out of 5, as in the single-population reading.

Inside the main population, the detector still flags values at its edges, between 5 and 10 per draw, among them the 3 intermediate amounts in 3 draws out of 5; read as one population, 4 or 5 values of the main group were flagged per draw, and none of the intermediate amounts. These are values to look at, not errors: a flag means “check this”, never “delete this”.

The image above shows the first draw as our detector draws it, with its two populations; the image below shows the same draw row by row, on a log scale, flagged values in red. In that draw 11 values are flagged: 10 at the edges of the main population, and the 7,000. None of the group around 3,000 is.

The same draw, row by row on a log scale: in red, the values our detector flags; the group around 3,000 is not flagged, the 7,000 is
The same draw, row by row on a log scale: in red, the values our detector flags; the group around 3,000 is not flagged, the 7,000 is

What it revealed at an insurer

On an engagement with an insurer, this detection did more than protect a group of values. In a column of claim amounts recorded under the same code, most claims were around ILS 200 and a few around ILS 3,000. The second population was not an error: it showed that the nomenclature was wrong, and that one code mixed several risks together.

For every variable where it finds several populations, the detector lists them in a table, which can be saved in Excel or CSV, with their count, their median and their range, and a note suggesting that the label, the nomenclature or the encoding be checked with the owner of the data. That table is what we put in front of the expert: it turns a statistical finding into a precise question about the business.

The encoding improves along the way. In insurance, data is often poorly encoded, and claims of different kinds end up under the same code. The impact on the claims department is direct: when two risks share a code, the frequency and the average cost computed for that code describe neither of them, and the prices and reserves built on it are distorted. Separating them while going through the data corrects the source, not just one analysis.

The limit

The protection requires a clear empty gap that sets the group apart from the other values, condition (2), and that gap is less often clear on large or widely spread tables, or when an extreme lies just above the group. The 3 intermediate amounts of our case do not fill it, which is why the group is still recognised. When the populations overlap, or when values bridge the gap, the detector no longer reports a second population: it judges the mixture as a whole, and the classical flagging applies, as for a single population.

This step is deliberately cautious and is not a general mixture detector: when the evidence is ambiguous, it prefers flagging unusual values to inventing a population. Its measured limits, on heavy tails and on rounded amounts, are set out in our article on outliers. The figures above come from one simulated shape of data and 5 draws: they show the behaviour, they do not prove it on every table.

What it changes in practice

A second population flagged as a block is a common way to lose information: a segment of payments set aside as errors, a price computed without it, a total that no longer reconciles. Recognising the populations first, then looking for anomalies inside each of them, keeps that segment in the analysis, while the genuinely unusual values, including one far above the second group, stay in front of the analyst.

Recognising populations is one difficulty of cleaning; scale is another. At SGTech, more than 10,000 sensor variables ranged from values of the order of 10⁻⁹ or smaller to values of the order of 10⁴, 10⁵ or more; the cleaning had to answer for every one of them before the PCA that brought out the variables linked to methane production, told in our article on PCA.

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