03 · Metrics
Accuracy
An exact answer to a question almost nobody meant to ask.
Accuracy has already been through this tutorial once. It carried the three settlements in the opening section, and it was exposed there as a cautionary tale. A number that hides a threshold, a cost and a prevalence, and that calls a model excellent for answering negative to everything.
This section gives it a fairer hearing, because that reputation is only half deserved. Accuracy is not broken and it is not biased. It is an exact statement about a specific decision, made under assumptions that are occasionally true.
Accuracy is a payoff
Accuracy is usually introduced as counting. How many did the model get right, out of how many were shown to it. Counting is what the arithmetic does, but it is not what the number means.
Let's visualize it in another way. Attach a value to each of the four outcomes before any counting starts. A correct call is worth
Now run the model over the population, look up each case in the table, and take the average of what comes back.
where
That average is accuracy. Not a count of correct answers, but the expected payoff of running this model on this population, under one particular schedule of payoffs. The schedule above has a name, it is the zero-one loss, so called because every mistake costs exactly one and every success costs nothing.
This is also the shape every metric in the later sections turns out to have. Net benefit is this table with different numbers in it. So is cost-sensitive accuracy, and so is the bounded score at the end of the tutorial. Once a metric is a payoff, the interesting question stops being how it is computed and becomes which payoffs it assumes.
The threshold the table implies
Section 01 left a threshold sitting at
Take a single case with score
Take whichever is larger. Predicting positive wins exactly when
which is the Bayes rule for the zero-one loss. The one half was never arbitrary after all. It fell out of the table, and it fell out because the table is symmetric: the two mistakes cost the same, so the tie sits in the middle. Put different numbers in the table and the tie moves.
A still threshold
There is a trap here and I think it's worth spending some time on it.
The rule above is optimal at any prevalence. Nothing in the derivation mentioned
It has not. The threshold is stable, but the quantity being thresholded is not.
Move the population and every posterior moves with it, so cases that used to sit above one half can drop below it without a single feature changing. Prevalence did not leave the decision. It moved out of the threshold and into the score. A later section makes that migration exact.
Without calibration, none of this holds
Every line above assumed
For such a score the accuracy-maximising threshold still exists, but it has to be found rather than derived: sweep
Biased is the wrong word
Here is the standard objection, stated as generously as it deserves:
On a dataset where ninety-nine percent of cases are negative, a model that answers negative every time scores
. Accuracy is therefore biased under class imbalance, and should be replaced by a metric that is robust to it.
The first sentence is arithmetic and it is correct. The advice at the end is broadly good as reporting a bare accuracy figure on a
Nothing here is biased
An estimator is biased when its average value across repeated samples differs from the quantity it is meant to estimate. Accuracy computed on a test set is an average of independent indicators, and its expected value is exactly the population accuracy it names. It is unbiased, at any prevalence, for any model, always.
The
Three complaints
The phrase covers three separate objections, and they have different causes and different cures.
- The number describes a population, not a model. Move to a population with a different mix and the number moves, which is what the opening section showed. That is real, but it is not bias. It is the metric correctly reporting a different quantity, because a different quantity is what was asked for. The cure is to state the prevalence, not to change metric.
- The estimate is noisy when one class is scarce. With forty positives in the test set, any number computed from those forty carries a wide interval. Also real, also not bias, and not about accuracy at all since it would harm recall, precision, or anything else estimated from the same forty cases.
- The payoff table is wrong for the problem. A missed case and a false alarm were entered as costing the same, and depending on the application they are not.
The third complaint is not about imbalance
Imbalance without the defect. Suppose the task is predicting whether a delivery arrives on a Tuesday, positives run at one percent, and the two mistakes genuinely cost the same because nothing much depends on either. Accuracy is fine. The
The defect without imbalance. Now take a perfectly balanced problem: half of the welds inspected have a flaw, half do not. A missed flaw eventually kills somebody. A false alarm costs an hour of re-inspection. Accuracy weights those two identically and is a catastrophic choice of metric, at
Imbalance is neither necessary nor sufficient for accuracy to mislead. What makes it mislead is a payoff table that does not match the application. Imbalance is merely the condition under which a bad table produces an embarrassing number rather than a merely wrong one, which is why the two get confused.
Why the confusion is expensive
A misdiagnosis leads to the wrong prescription. If the problem is believed to be imbalance, the cure looks like finding a metric that is robust to imbalance, and the search ends at whichever metric moves least when the mix changes. If the problem is understood as a wrong payoff table, the cure is to write down the right one.
What cannot be repaired
Only one of the three complaints was about accuracy itself, and it was the payoff table. So correct it. Work out what a missed case is worth, put that number in, and carry on.
That works, and it is the end of accuracy. The values
So why is it always low prevalence
Imbalance is neither necessary nor sufficient, and that stands. Low prevalence is still where accuracy fails nearly every time, for three unrelated reasons.
- Rarity and asymmetry travel together. Things are usually rare on account of being bad: disease, fraud, fracture, default. Low prevalence does not imply a broken table. It predicts one.
- The scale collapses. At
everything worth arguing about is packed into the last hundredth, so large real differences surface in the third decimal place. - The measurement gets noisy. The
half is estimated from however many positives the test set happened to hold. A later section is devoted to this.
The first needs a cost, the second a baseline, the third more positives. None of them is answered by a metric that moves less when the class mix changes.
If accuracy is reported anyway, print
Balanced accuracy, next, leaves the payoff table exactly where it is and changes the prevalence instead.