Top-k accuracy is a classification metric that counts a prediction as correct when the true label appears among the k highest-scoring classes the model outputs, rather than requiring it to be the single top prediction. In model evaluation, it measures how well a model ranks the right answer near the top, which matters for tasks with many classes, ambiguous labels or ranked suggestions.
The most common variants are top-1 accuracy, which equals ordinary accuracy, and top-5 accuracy, which became standard through the ImageNet Large Scale Visual Recognition Challenge with its 1,000 object categories. Top-k accuracy is always greater than or equal to top-1 accuracy and rises monotonically as k grows.
How top-k accuracy is calculated
Top-k accuracy is calculated by sorting the model scores for each example, keeping the k highest-ranked classes and checking whether the true class is among them. The metric is the fraction of examples with a hit, expressed as a value from 0 to 1 or as a percentage.
Formally, for N examples, top-k accuracy equals the number of examples where the correct label is in the top-k set, divided by N. The scores can be logits, softmax probabilities or any other ranking values, because only their order matters. Ties at the k-th position need a defined tie-breaking rule, since different libraries resolve them differently.
The table below shows a small worked case with five examples and k set to 3.
| Example | True class | Top three predictions | Top-1 hit | Top-3 hit |
|---|---|---|---|---|
| 1 | Cat | Cat, lynx, dog | Yes | Yes |
| 2 | Wolf | Husky, wolf, coyote | No | Yes |
| 3 | Fox | Dog, cat, rabbit | No | No |
| 4 | Owl | Owl, hawk, eagle | Yes | Yes |
| 5 | Moth | Butterfly, bee, moth | No | Yes |
In this case, top-1 accuracy is 40 percent and top-3 accuracy is 80 percent. The gap between the two values shows that the model often knows the neighborhood of the answer but misorders close alternatives.
Common values of k and where they apply
The choice of k should match how the predictions are consumed. A value of k that is larger than any real user or system would inspect makes the metric look strong while saying little about practical usefulness.
| Variant | Typical domain | Why this k is used |
|---|---|---|
| Top-1 accuracy | Automated decisions | Only one answer is acted upon |
| Top-3 accuracy | Suggestion interfaces, triage | Users scan a short list |
| Top-5 accuracy | Large-scale image classification | Classes overlap and labels are ambiguous |
| Top-10 accuracy | Retrieval, recommendation | Results appear as ranked pages |
| Top-k by class count | Thousands of classes | Normalizes difficulty across tasks |
Top-5 accuracy became popular for ImageNet because many images contain several valid objects and some categories, such as related dog breeds, are hard even for people to separate. Leading image classifiers now exceed 97 percent top-5 accuracy on ImageNet, which is why top-1 accuracy has become the more informative headline figure there.
Top-k accuracy compared with related metrics
Top-k accuracy is a ranking-aware relaxation of accuracy, but it ignores the exact position of the correct class within the top k and ignores the confidence of the prediction. Related metrics capture those missing aspects.
| Metric | What it measures | Key difference from top-k accuracy |
|---|---|---|
| Accuracy | Correct single prediction | Equivalent to top-1 accuracy |
| Mean reciprocal rank | Position of the first correct item | Rewards higher placement within k |
| Recall at k | Share of all relevant items in top k | Handles several correct answers |
| pass@k | At least one of k samples passes tests | Uses sampled generations, not class scores |
| Model calibration | Agreement of confidence and correctness | Evaluates probabilities, not ranking |
Top-k accuracy and recall at k coincide when each example has exactly one relevant item. They diverge in multi-label and retrieval tasks, where recall at k counts how many of several correct items were found, while top-k accuracy only records whether at least one was found.
Choosing and reporting top-k accuracy
Top-k accuracy should be reported together with top-1 accuracy and with the value of k stated explicitly. A single top-k figure without context hides whether the model is decisive or merely produces a plausible shortlist.
The following table connects typical evaluation situations to a reporting choice.
| Situation | Recommended reporting | Reason |
|---|---|---|
| Fully automated pipeline | Top-1 accuracy as the primary metric | Only the first answer has effect |
| Human picks from suggestions | Top-k with k equal to list length | Matches the real interface |
| Imbalanced classes | Per-class or macro top-k | Prevents frequent classes from dominating |
| Model comparison | Top-1 and top-5 side by side | Shows ranking quality and decisiveness |
| Risk-sensitive decisions | Add calibration metrics | Top-k ignores confidence errors |
For imbalanced datasets, an overall top-k score can stay high even when rare classes are almost never ranked correctly. Computing a macro-averaged top-k accuracy, in which each class contributes equally, reveals this weakness and pairs well with error analysis by class.
Limitations and common mistakes with top-k accuracy
Top-k accuracy rewards a model for placing the correct label anywhere in the shortlist, so it can mask poor discrimination between similar classes. A model that consistently ranks the right answer fifth earns the same top-5 score as one that ranks it first.
- Trivial ceilings: with few classes, a large k makes the metric meaningless; k equal to the class count always yields 100 percent.
- Inconsistent tie handling: equal scores at rank k can change results between frameworks.
- Label noise effects: wrong ground-truth labels cap achievable accuracy and blur model comparisons.
- Benchmark saturation: when most models exceed 95 percent, differences fall within noise.
- Distribution shift: a strong top-k score on a validation set may not hold on new data.
Another frequent mistake is comparing top-k values across datasets with different numbers of classes. Top-5 accuracy on a 10-class problem and on a 1,000-class problem describe very different levels of difficulty, so comparisons are only valid within the same label space.
The short version
Top-k accuracy asks a simple question: was the right answer on the model’s shortlist? Instead of judging only the first guess, it lets the model offer its best few guesses, such as five, and counts a success if any of them is correct.
Think of a quiz contestant allowed three guesses. Scoring by three guesses is fairer when answers are easily confused, but it also says less about whether the contestant truly knows the answer. That is why experts usually report both the first-guess score and the shortlist score.
Where it makes a difference
A hospital pathology department tests an image model that suggests the likely tissue diagnosis from microscope slides across 40 categories. The pathologist always makes the final decision and sees the model’s three top suggestions on screen, so the team evaluates the model with top-3 accuracy alongside top-1 accuracy.
On a held-out set of 2,000 slides, the model reaches 78 percent top-1 accuracy and 95 percent top-3 accuracy. Per-class analysis, however, shows that two rare tumor subtypes appear in the top three for only about 60 percent of their cases.
The department deploys the tool as a shortlist aid, adds a warning for the weak subtypes and schedules additional labeled data for them. Reporting top-3 accuracy made the real workflow value visible, while the per-class breakdown prevented an overly optimistic headline figure from hiding a clinically important gap.