Top-k accuracy

Also known as: top-5 accuracy

On this page 7

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.

ExampleTrue classTop three predictionsTop-1 hitTop-3 hit
1CatCat, lynx, dogYesYes
2WolfHusky, wolf, coyoteNoYes
3FoxDog, cat, rabbitNoNo
4OwlOwl, hawk, eagleYesYes
5MothButterfly, bee, mothNoYes
Worked example of top-3 accuracy

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.

VariantTypical domainWhy this k is used
Top-1 accuracyAutomated decisionsOnly one answer is acted upon
Top-3 accuracySuggestion interfaces, triageUsers scan a short list
Top-5 accuracyLarge-scale image classificationClasses overlap and labels are ambiguous
Top-10 accuracyRetrieval, recommendationResults appear as ranked pages
Top-k by class countThousands of classesNormalizes difficulty across tasks
Typical choices of k

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 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.

MetricWhat it measuresKey difference from top-k accuracy
AccuracyCorrect single predictionEquivalent to top-1 accuracy
Mean reciprocal rankPosition of the first correct itemRewards higher placement within k
Recall at kShare of all relevant items in top kHandles several correct answers
pass@kAt least one of k samples passes testsUses sampled generations, not class scores
Model calibrationAgreement of confidence and correctnessEvaluates probabilities, not ranking
How top-k accuracy relates to neighboring metrics

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.

SituationRecommended reportingReason
Fully automated pipelineTop-1 accuracy as the primary metricOnly the first answer has effect
Human picks from suggestionsTop-k with k equal to list lengthMatches the real interface
Imbalanced classesPer-class or macro top-kPrevents frequent classes from dominating
Model comparisonTop-1 and top-5 side by sideShows ranking quality and decisiveness
Risk-sensitive decisionsAdd calibration metricsTop-k ignores confidence errors
Decision guide for top-k reporting

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.