Your Classifier Is Confidently Wrong: An Introduction to Out-of-Distribution Detection

title: "Your Classifier Is Confidently Wrong: An Introduction to Out-of-Distribution Detection" published: true tags: machinelearning, ai, deeplearning, datascience series: Out-of-Distribution Detection cover_image: https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/hrj7xa96n8rg3bwz31tr.png canonical_url: https://oasolomon.vercel.app/blog/your-ai-is-confidently-wrong-and-it-cant-even-tell
Train a classifier to tell cats from dogs and it can hit near-perfect accuracy on held-out images. Now show it a car. It will still answer, something like "dog, 92% confident", even though a car is neither.
That isn't a bug in one model. Every standard classifier is built to do this.
The forced choice
A standard classifier has no output for "I don't know." Its last layer, the softmax, turns raw scores into probabilities that sum to 1, so whatever you feed it (a car, a handwritten digit, a scan from a hospital it has never seen) has to land in one of the classes it knows.
So the confidence it reports tells you which known class the input looks most like. It says nothing about whether the input belongs to any of them. Hendrycks and Gimpel made this point in 2017 when they proposed the maximum softmax probability as an out-of-distribution baseline: it works better than nothing, it is easy to beat, and nearly ten years later it is still the number every new method gets compared against.

What out-of-distribution detection adds
Out-of-distribution (OOD) detection puts a second check next to the classifier. It has two pieces:
- A score that says how familiar each input is. High means familiar, low means strange.
- A threshold on that score. Anything below it gets flagged instead of trusted.
Most of the research in this area is about those two pieces: how to define the score, and where to put the line.

Near and far OOD
Some strange inputs are much stranger than others.
A handwritten digit shown to a dog classifier is far OOD. Its features look nothing like the training data, and almost any score catches it.
A wolf is near OOD, and it's the hard case. Fur, ears and snout all overlap with dogs, so the model is at its most confident exactly where it should be most careful.
Existing methods mostly handle far OOD. Near OOD is still open, and it's the kind you actually meet after deployment: a new variant of a disease, a road sign from another country, a product photographed under different lighting.
The common scores
Four families of scores keep showing up in papers:
- MSP (maximum softmax probability). The model's top confidence. Free to compute, and the baseline from Hendrycks and Gimpel (2017). It's weak, and everything else is measured against it.
- Energy. Computed from the raw logits instead of the normalised probabilities (Liu et al., 2020). It separates familiar from strange more cleanly than MSP and costs nothing extra.
- Feature distance. These skip the final prediction and look at where the input lands inside the network, measuring how far it sits from the training examples with Mahalanobis distance (Lee et al., 2018) or nearest neighbours (Sun et al., 2022). Far from everything the model has seen means flagged.
- ViM (virtual-logit matching). Mixes feature distance with residual analysis. It measures the part of the input's features that the classifier's own directions can't explain, and uses that leftover as the signal (Wang et al., 2022).


None of these retrain the model. Each one reads an already-trained model and asks, in its own way, whether an input looks like the training data.
How the scores are judged
Two metrics do most of the work.
AUROC measures how well a score separates familiar inputs from strange ones. 50% is a coin flip and 100% is perfect separation.
FPR95 asks: once the threshold is set to catch 95% of the strange inputs, what fraction of normal inputs get flagged by mistake? Lower is better. This is the one users feel, because every false flag is a legitimate request the system refuses to answer.

Why bother
A medical model that confidently misreads a scan from a new hospital, a driving system that confidently misreads an unfamiliar road sign, a moderation filter that waves through content it has never seen: in all three, a confident mistake costs far more than handing the case to a person.
OOD detection won't make a model more accurate. What it gives you is a way to see when the model is out of its depth, so you can route those inputs somewhere else.
What's still unsolved
Near OOD is still hard. The best scores separate far OOD almost perfectly and near OOD only partly.
The threshold needs representative data. Set it on the wrong data and the system flags everything or nothing.
And no score wins everywhere. One that tops the table on one dataset and model can be mediocre on the next, which is why papers benchmark several side by side. The next post goes through the five most common scores one at a time.
Have you caught a model being confidently wrong on something outside its training data? What was it, and what did you do about it?