The Standard Score
How unusual is a measurement that is ten units above average? That depends on how much the measurements usually vary. A standard score expresses the difference in units of standard deviation.
14 sections · 15 questions · 4 coding challenges
The arrow keys move between sections too.
Is That a Large Difference for This Measurement?
BOTIE
Nineteenth-century work on measurement errors and biological variation developed ways to describe the spread of observations. Pearson's 1894 study of frequency curves, for example, used standard deviation while examining how measured populations were distributed. Standard scores draw on that tradition of describing an observation relative to both a centre and a scale.
First we measure the departure from the mean. Then we express that departure in units of the group's standard deviation. A score now tells us how far from the centre an observation lies on that scale. This makes different measurements easier to compare, but it does not make their distributions identical or turn an unusual observation into an error.
Sources for this history
How Unusual Is That Number?
Being ten units above average means something different in a tightly gathered group than in a widely scattered one. We need a ruler that accounts for the variation in the quantity we measure.
A standard score chooses the average as zero, then uses the training standard deviation as the unit.
Raw units do not describe unusualness
An orchard records trunk girth and water supplied in different units. Larger written numbers do not automatically deserve more influence. Their size partly comes from the choice of unit.
Trunk girth
- Millimetres
Water supplied
- Metres
The formula combines two separate changes
Subtracting changes the reference point; dividing changes the unit. We will calculate those steps separately before combining them.
The orchard example shows how standardized coordinates affect neighbour comparisons. A constant column requires an explicit rule because its standard deviation is zero.
Explore the full example
Compare each original value with its standard score. Identify the mean at zero and check what one unit on the new scale represents.
average trunk
…
its spread
…
average score
…
spread of the scores
…
…
Part 1. When the Unit Decides the Answer
1. Twenty-four trees, two units
The orchard this page works through is twenty-four apple trees. Each one was measured twice before the harvest, its trunk girth written down in millimetres and the water it was given over the season written down in metres, and then the fruit it bore was weighed in kilograms. Both units are ones somebody could reasonably have chosen, and neither is wrong; what matters is that they are a thousand apart, so the trunk numbers run in the hundreds while the water numbers run below one.
| column | smallest | largest | average | spread |
|---|---|---|---|---|
| trunk girth, millimetres | 202 | 620 | 387.625 | 113.652 |
| water, metres | 0.41 | 0.95 | 0.679 | 0.172 |
One spread is 659.21 times the other, and nothing about the trees produced that number. Writing the water in millimetres instead would reverse it.
The two columns are very nearly unrelated to each other, their correlation being −0.083, and they are not at all equally useful. Water very nearly decides the fruit; the trunk barely moves it. That combination is what makes the orchard worth measuring on, since the column recorded in the larger numbers is also the column that carries almost nothing.
Keep in mind
2. The nearest trees the recorded columns choose
Take one tree and ask which three trees in the orchard are most like it, then predict its fruit as the average of what those three bore. The likeness has to be a number, and the usual one adds up the gap in each column after squaring it, so a difference of seven millimetres of trunk and a difference of a third of a metre of water are added together with nothing standing between them.
distance² = (trunk gap in mm)² + (water gap in m)²…
The wettest tree in the orchard
That tree has a trunk of 369 mm, was given 0.95 m of water, the most of any tree, and bore 55.14 kg, the most of any tree. Asked in the recorded units, its three nearest are the trees of 362, 359 and 354 mm, whose water was 0.59, 0.48 and 0.52 m, and the trunk column owned between 0.9974 and 0.9992 of every one of those squared distances.
Their average fruit is 33.84 kg, which is 21.30 kg short. Asked in standard scores the three nearest were given 0.91, 0.90 and 0.93 m, their average fruit is 52.73 kg, and the answer is 2.41 kg short.
Keep in mind
3. Why one column owns the distance
The reason is arithmetic rather than bad luck, and it can be written in one line. Rewriting a column in a unit a thousand times smaller multiplies every gap in that column by a thousand, and a squared distance sees the square of that, so the column’s say in the total is multiplied by a million. What decides the balance between two columns is therefore the ratio of their spreads, squared.
girth spread / water spread = 113.652 / 0.172 = 659.21
the same ratio squared = 434,551›Why this works
A typical gap in a column is about the size of that column’s spread, so a typical squared gap is about the square of the spread. The two columns contribute to a squared distance in roughly the proportion of those two squares, which here is four hundred thousand to one. The whole width of the water column, 0.54 metres from the driest tree to the wettest, counts for exactly what 0.54 of a millimetre of trunk counts for, since the sum is handed two numbers and no units at all.
Keep in mind
4. The wrong answer, measured
One tree is an anecdote, so the same question is put to all twenty-four. Each tree in turn is held out, the fit is rebuilt on the other twenty-three, and the twenty-four predictions are then scored together against the twenty-four true weights. The score is the usual one, where 1 means every prediction was exact and 0 means the fit did no better than answering the orchard’s average weight to every tree, so a negative score means it did worse than that.
| three nearest trees, chosen | score over all twenty-four |
|---|---|
| in millimetres and metres, as recorded | −0.7175 |
| in standard scores | 0.9126 |
| by the water column alone, unstandardized | 0.9544 |
| by the trunk column alone, unstandardized | −0.7238 |
The recorded reading scores almost exactly what the trunk column alone scores, which is what it means to say that the unit chose the column.
Keep in mind
Part 2. Subtract the Average, Divide by the Spread
5. The two numbers a column teaches
The repair is one line, applied to each column on its own. Work out the column’s average and its spread, take the average away from every value, and divide what is left by the spread. Those two numbers are the whole of what a column teaches, and the value that comes out is called the standard score of the value that went in.
z = (value − average) / spreadThe spread here is the standard deviation, which is the square root of the average squared distance from the average. The playground at the top of the page is that line drawn twice. The upper line holds trunk girths in millimetres and the lower line holds the same trunks in standard scores, both on rulers that stay put, so a dot that falls off either end is drawn faint at the end it fell off. Drag a trunk about and watch how differently the two lines answer.
Keep in mind
6. Five saplings by hand
Press the nursery row button on the playground. Five saplings were measured at 210, 210, 260, 160 and 310 millimetres, and the whole arithmetic comes out in whole numbers as far as the square root. The average first.
210 + 210 + 260 + 160 + 310 = 1150, 1150 / 5 = 230The nursery row, all the way through
The five distances from 230 are −20, −20, 30, −70 and 80, whose squares are 400, 400, 900, 4900 and 6400. Those add to 13,000 and their average is 2600, which is the variance, and the spread is its square root.
400 + 400 + 900 + 4900 + 6400 = 13,000
13,000 / 5 = 2600, √2600 = 50.990195Now divide each of the five distances by 50.990195, which is the whole of the transformation.
−20 / 50.990195 = −0.392232
−20 / 50.990195 = −0.392232
30 / 50.990195 = 0.588348
−70 / 50.990195 = −1.372813
80 / 50.990195 = 1.568929The two saplings of 210 mm come out at the same number, which they must, since the transformation asks nothing about a value except what it is. The 160 mm sapling is the furthest from typical of the five, at 1.37 spreads below the average, and the 310 mm one is 1.57 above.
Keep in mind
7. What the transformation promises
Two things are true of the transformed column whatever went into it. Its average is exactly zero and its spread is exactly one. Both fall out of the definition in a line each, which is worth doing because the second one is where a convention hides.
zᵢ = (xᵢ − m) / s
average(z) = (1/n) Σ (xᵢ − m) / s = (1/s)(m − m) = 0
variance(z) = (1/n) Σ (xᵢ − m)² / s² = s² / s² = 1›Why this works
The first line is the transformation, with m for the average and s for the spread. The second says that the distances from an average always cancel, which is what makes an average an average, so dividing them all by one number leaves them cancelling still. The third is the whole argument. The average of the squared distances is s² by the definition of s, and dividing every distance by s divides that average by s², which leaves exactly one.
The nursery row shows both. Its five standard scores average to 0 and their variance is 1, printed by the playground as an average of 0.000 and a spread of 1.000.
Keep in mind
8. The unit has gone
The claim that the standard score removes the unit can be checked rather than believed. Write every trunk in centimetres instead of millimetres, which divides each value by ten, and the average and the spread are divided by ten as well, so the quotient is untouched. Add a thousand millimetres to every trunk and the average moves by exactly a thousand while the spread does not move at all, so again the quotient is untouched.
(a·x + b − average(a·x + b)) / spread(a·x + b) = a(x − average(x)) / (a · spread(x))The nursery row moved twice
The five saplings are the whole-number column 1, 1, 2, 0, 3 stretched by 50 and shifted by 160, and standardizing that whole-number column gives −0.392232, −0.392232, 0.588348, −1.372813 and 1.568929, which are the five scores worked out above. The largest disagreement between the two sets is 2.2 × 10⁻¹⁶, which is the last bit of a number near one and is what dividing by two different numbers costs. On the orchard’s twenty-four trunks, adding a thousand millimetres to every one of them changes the largest score by exactly zero.
Keep in mind
Check yourself
Questions on Parts 1 and 2
Question 1 of 5
Rewriting a column in a unit a thousand times smaller multiplies every gap in it by a thousand. What does that do to its say in a squared distance?
Part 3. A Value Measured in Its Own Deviations
9. What a standard score says
A standard score of 2 says that the value is two spreads above what is typical for its column. That is a sentence about the column as much as about the value, and it is the reason the number is worth having. A trunk of 620 millimetres tells you nothing on its own unless you keep orchards; a trunk 2.04 spreads above the average trunk in this orchard tells you at once that it is among the widest here and not absurdly so.
(620 − 387.625) / 113.652 = 2.0446Keep in mind
10. Two unrelated columns become comparable
Millimetres of trunk and metres of water cannot be compared. There is no question that 620 and 0.95 both answer, so asking which of the two readings is the more unusual has no meaning at all while they are in their own units. In standard scores the same question has an answer, because both numbers are now counts of the same kind of thing, namely how far a value is from typical measured in that column’s own spreads.
…
The same change reaches the summary of how two columns move together. Once both are in standard scores their covariance is their correlation, since a correlation is exactly a covariance with each column’s spread divided out; measured on the orchard the two numbers agree to sixteen decimal places, both coming to −0.0826.
The widest trunk against the wettest tree
The widest trunk in the orchard is 620 mm, which is 2.04 spreads above the average trunk. The most water any tree was given is 0.95 m, which is 1.57 spreads above the average drink. So the widest trunk is the more unusual of the two readings, by about half a spread, and no arrangement of the raw numbers could have told you that.
The tree with the widest trunk is also the one that most needed telling apart from the rest, since it was given only 0.47 m of water, a reading 1.21 spreads below average, and it bore 30.82 kg.
Keep in mind
11. Weights that can be ranked
The same comparability reaches the fitted weights of a line. A line fitted on the recorded columns puts a weight on trunk girth measured in kilograms per millimetre and a weight on water measured in kilograms per metre, and those two weights cannot be ranked against each other any more than the raw readings could. Fitted on standard scores, both weights are in kilograms per spread of their own column, and the ranking is then a real one.
…
The orchard’s line in two coordinate systems
On the recorded columns the weights are 0.0038802 on the trunk and 49.560 on the water, a ratio of nearly thirteen thousand, which describes the units and not the trees. On standard scores they are 0.4410 and 8.5446, a ratio of 19.375, which says that moving a tree one spread along the water column is worth about nineteen times as much fruit as moving it one spread along the trunk column. Dividing each standardized weight by its column’s spread returns 0.0038802 and 49.560, so the two fits are one line described twice.
Keep in mind
12. How far out is far out
Since a standard score is a count of spreads, it is tempting to reach for the familiar figures, that about two thirds of a column falls within one spread and about nineteen twentieths within two. Those figures belong to the bell curve and not to the standard score, and the orchard shows the difference without being unusual in any way.
| column | within one | within two | within three |
|---|---|---|---|
| trunk girth | 0.6667 | 0.9583 | 1.0000 |
| water | 0.5833 | 1.0000 | 1.0000 |
| a bell curve | 0.6827 | 0.9545 | 0.9973 |
The trunks come close to the bell figures by accident and the water column does not, being flatter than a bell and therefore holding less of itself near the middle.
There is one statement about standard scores that holds for every column whatever its shape. At most one part in k squared of a column can lie further than k spreads from the average, so at least three quarters of any column at all is within two spreads and at least eight ninths is within three. Both columns clear that comfortably, which they must.
share beyond k spreads ≤ 1 / k²Keep in mind
Part 4. Which Fits Need It and Which Do Not
13. Anything that adds columns together
The split runs along one line, and the line is whether the fit ever adds a quantity from one column to a quantity from another. A squared distance does exactly that, so every fit built on distances is at the mercy of the units, and Part 1 measured how badly. The same sum is inside k-means, whose centres are chosen to minimise it, and inside principal component analysis, whose first direction follows whichever column happens to have the largest variance in whatever unit it was recorded in.
…
Keep in mind
14. Anything that penalises a weight
A penalised line adds the squared size of every weight to what it is trying to make small, so the weights compete against one number. A column recorded in a large unit needs a small weight to do its work, and a small weight is cheap under the penalty, so the penalty falls unevenly for a reason that has nothing to do with the trees.
One penalty over the orchard
At a penalty of one on the recorded columns, the weight on water is squeezed from the 49.56 that least squares wanted down to 20.55, because 49.56 is an expensive number to hold, and the fit’s score falls from 0.9845 to 0.6475. On standard scores the same penalty takes the water weight from 8.5446 to 8.1992 and the score to 0.9828. Held out tree by tree, the recorded fit scores 0.5452 and the standardized one 0.9768.
Keep in mind
15. A tree never notices
A decision tree compares values only within a column. Every question it asks is whether a value falls below a threshold, and the apple trees that go left when asked about 0.665 metres go left when asked about −0.082 spreads, because the threshold was chosen from the same column that was rescaled and moves along with it.
…
The same tree twice
Grown on the recorded columns to a depth of three, the tree roots on whether water is below 0.665 and has eight leaves. Grown on standard scores it roots on whether water is below −0.08217, which multiplied by the water spread and put back about the average water is 0.665. The largest gap between the two sets of twenty-four predictions is exactly zero, and both score 0.8940 held out tree by tree.
Keep in mind
16. Least squares never notices either
The more surprising member of the untouched group is the plain least-squares line, which does add the columns together and still does not care. The reason is that it has a free weight per column and nothing stopping it from choosing whatever weight the unit calls for. Multiply a column by a hundred and the fitted weight is divided by a hundred, the fitted values are identical, and the score does not move.
The orchard’s line, recorded and standardized
Both fits score 0.98445555, and the gap between the two scores is exactly zero rather than merely small. Held out tree by tree, both score 0.97911. That is the same objective the penalised fit above was minimising, with one term added, and the added term is what broke the property.
Keep in mind
17. Where standardizing is the wrong move
Standardizing gives every column an equal say, and an equal say is not always the say a column deserves. The orchard makes that concrete, since its trunk column carries almost nothing about the fruit and standardizing hands it half of every distance.
| three nearest trees, chosen | score over all twenty-four |
|---|---|
| by both columns, as recorded | −0.7175 |
| by both columns, in standard scores | 0.9126 |
| by the water column alone | 0.9544 |
Dropping the useless column beats standardizing both of them by 0.042, and it takes no fitting at all.
So the honest ordering on this orchard puts the standard score second. It repaired a fit that was worse than a constant and it did not reach what simply knowing which column mattered would have reached. What it bought is that it needed no such knowledge, which is the trade being made whenever a column whose worth is unknown is standardized rather than dropped.
Keep in mind
Check yourself
Questions on Parts 3 and 4
Question 1 of 5
The widest trunk is 2.04 spreads above the average trunk, and the wettest tree was given water 1.57 spreads above the average drink. Which reading is the more unusual?
Part 5. The Two Numbers Belong to the Training Rows
18. Learn on the rows the fit saw
A standard score is not a property of a value. It is a property of a value and a column together, and which column is a real choice when some rows are held back to test on. The rule is that the average and the spread are worked out from the training rows alone and then applied unchanged to everything afterwards, whether that is a held-out tree, a tree planted next season, or a training tree put through again.
held-out score = (held-out value − training average) / training spreadKeep in mind
19. Measuring held-out rows against themselves
The tempting alternative is to standardize the held-out rows with their own average and their own spread, which looks like the same operation and is a different one. Take the four wettest trees out of the orchard, fit on the twenty that remain, and then read the four both ways.
…
Four trees that were all wet
The twenty kept trees have an average drink of 0.6305 m and a spread of 0.1462, so the four held-out trees come out at 2.05, 2.18, 1.84 and 1.91 spreads above average, which is the right description of four trees that were the wettest in the orchard. Standardized against themselves they come out at 0.39, 1.43, −1.17 and −0.65, announcing that two of the four wettest trees in the orchard were drier than average, because the only average they were compared with was their own.
Put through the line fitted on the twenty, the first reading predicts 54.81, 56.10, 53.73 and 53.94 kg against true weights of 53.00, 55.14, 52.10 and 53.08, worst error 1.81 kg. The second predicts 42.15, 50.64, 31.63 and 34.73, worst error 20.47 kg.
Keep in mind
20. Learning the numbers over everything, measured
There is a milder version of the same mistake, and it is the common one. Standardize the whole orchard first, then split it into folds and cross-validate. Nothing is refitted on the held-out rows, so the disaster of the last step does not happen, and yet the two numbers were computed with the held-out rows in the sum, so each fold’s columns carry a trace of the tree that fold was about to be tested on.
…
What the trace was worth here
Held out tree by tree, the largest difference any of the six fits showed was 0.0037, on the heavily penalised line, and it went the wrong way, the leaked version scoring slightly worse rather than better. The nearest-neighbour fits and the tree and the least-squares line all showed a difference of exactly zero. So on this orchard the leak flattered nothing at all, and saying otherwise would be dramatising a number I measured and found to be nothing.
Two of those zeros are exact for a reason worth keeping. A tree and a least-squares line are untouched by any affine rescaling of a column, as Part 4 measured, so which rows the average and the spread were read from cannot possibly reach them. The zeros for the nearest-neighbour fits are not guaranteed by anything; they say that dropping one tree of twenty-four did not move the two numbers enough to change any ranking of distances.
Keep in mind
21. What the transformation does not fix
Subtracting an average and dividing by a spread moves a column and rescales it and does nothing else whatever. Every value keeps its place in the order, every gap keeps its size relative to every other gap, and the picture of the column is the same picture with different numbers written under it.
…
A column with a long tail
Fifteen readings running 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 6, 9, 20 are strongly lopsided to the right, and the usual measure of that lopsidedness is 2.4896725430. After standardizing it is 2.4896725430, agreeing to the last bit the arithmetic keeps, and the order of the fifteen is unchanged. The 20 was the value furthest from typical before and it is the value furthest from typical after, now called 3.34.
Keep in mind
Part 6. Where the Standard Score Stops Being Defined
22. A column with no spread
Every value in the column is 300. Its average is 300, every distance from that average is exactly zero, and so the spread is exactly zero. The standard score of any of those values is therefore zero divided by zero, which has no value at all. The same holds for a column of one value, since one value is always its own average and so its one distance from it is zero.
| the column | what the arithmetic says |
|---|---|
| 300, 300, 300, 300 | every distance from the average is 0, so the spread is 0 and each score is 0 / 0, which has no value. Nothing about the column is wrong; the quotient simply does not exist. |
| 300 | the same, reached differently. One value is its own average, so its one distance is 0. With the other convention for the spread, dividing the sum of squares by one fewer than the count, the variance itself is 0 / 0 before any square root is taken. |
| 300, 300.0000000000001 | defined, and the boundary is that sharp. The spread is 5.7 × 10⁻¹⁴, which is positive, so the two values come out at exactly −1 and 1, as any two distinct values must. |
Because the quotient does not exist, an implementation has a genuine choice to make rather than a bug to avoid, and the three answers in use cost different things. Refusing tells the caller at once that a column they thought was informative is not, and stops a fit that was about to be built on nothing.
Substituting a spread of one and passing the column through turns it into a constant column of zeros, which most fits ignore and a penalised fit charges nothing for, so the run completes and nobody learns anything about the data. Dropping the column silently changes how many columns come out of the transformation, which breaks anything downstream that matched columns by position.
Keep in mind
23. A spread of almost nothing is still a spread
The boundary between defined and undefined is a single point and the arithmetic sits right up against it. Nine readings each one machine epsilon further along than the last have a spread of about 2.6 × 10⁻¹⁶, which is positive, so every one of the nine has a standard score and they run evenly from −1.55 to 1.55.
…
There is nothing in the numbers that says whether those nine readings differ because the quantity really varies at that scale or because a sum somewhere lost its last bits. Answering the first way spreads nine indistinguishable values across the full width of the ruler and hands a fit nine confident positions built out of rounding. Answering the second way, which some implementations do by treating any spread below a few machine epsilons as zero, leaves a column whose values genuinely differ at that scale looking constant.
Keep in mind
24. The values most in need of taming set the scale
Both numbers the transformation uses are sums over every value in the column, so both can be moved a long way by a single value. That is awkward in a particular way here, since the reason for reaching for a standard score is often that one column contains something extreme, and the extreme value is the one deciding what typical means and what a spread is.
…
One trunk typed with a stray digit
The orchard’s trunk of 438 mm typed as 4380 moves the average trunk from 387.6 to 551.9 and the spread from 113.7 to 806.2. The widest real trunk in the orchard, 620 mm, read 2.04 spreads above average and now reads 0.08. The other twenty-three trees, which spanned 3.68 spreads between them, are pressed into 0.52 of a spread, all sitting between −0.43 and 0.08, while the mistyped trunk sits alone at 4.75.
Notice what did and did not happen. The transformation is still exactly correct, the scores still average zero and still have a spread of one, and the mistyped value is still marked as the odd one, which is genuinely useful. What is lost is every distinction among the twenty-three real trees, which a fit reading these scores can no longer see.
Keep in mind
25. Standard does not mean normal
The last thing the transformation does not say is the one its name most invites. A standard score is defined for any column whose spread is positive, and the definition never mentions a bell curve, a symmetry or a shape. Standardizing a column that is nothing like a bell gives a column that is nothing like a bell, with an average of zero and a spread of one.
| fifteen readings with a long tail | as recorded | in standard scores |
|---|---|---|
| lopsidedness | 2.4896725430 | 2.4896725430 |
| share within one spread of the average | 0.8667 | 0.8667 |
| furthest value, in spreads | 3.3423 | 3.3423 |
A bell curve would put 0.6827 of itself within one spread, and these readings put 0.8667 there before and after, since the transformation had nothing to say about the shape.
Two habits follow from the confusion and both are worth breaking. Reading a score of 3 as one in a thousand assumes a bell; on the fifteen readings above, a score of 3 is exceeded by one value in fifteen. And treating a fit as ready for a method that assumes normality because its columns have been standardized skips the step that method actually needed, which is a transformation of the shape rather than of the location and the scale.
Keep in mind
Check yourself
Questions on Parts 5 and 6
Question 1 of 5
The four wettest trees are held out and the fit is built on the twenty that remain. Standardized against their own average and their own spread, what do those four report?
Try it with Botie
Build with Botie
Write and run Python