AI Glossary / Causal inference and experimentation / Beginner
Top-k accuracy
Definition
Top-k accuracy is the proportion of evaluated examples for which the target label appears among the k highest-ranked predictions. In ordinary single-label classification, the target is the correct class. Top-1 accuracy checks only the first prediction; larger k values allow a longer shortlist.
What it means
A model can be useful when it places the correct answer in a small set for a person or another process to review, even if it does not rank that answer first. Top-k accuracy measures this shortlist coverage.
It does not measure whether the reviewer eventually chooses correctly, whether the list contains misleading alternatives, or how much effort the list requires. The value of k should therefore reflect the actual workflow.
Some applications use a designated target item rather than an independently established correct class. In those settings, explain what the target represents. A hit on a chosen item and ordinary classification correctness need not be the same claim.
How it works
For each example, rank candidate labels by the model's scores. Select the first k distinct labels and record one if the target is included, otherwise zero. Average those indicators, or apply a documented weighting scheme.
Scores can be probabilities or compatible decision values because the calculation depends on ordering. Their columns must match the intended class labels. Tied scores at the cutoff need an explicit convention; different implementations can resolve ties differently.
For a fixed complete ranking, increasing k cannot reduce top-k accuracy. If k includes every possible class, the metric becomes trivially perfect when the target is in that class universe. Comparisons therefore need the same k, candidate universe and evaluation protocol.
Three practical examples
- A photo-identification tool offers three candidate species and measures whether the reference species appears in that shortlist.
- A document-routing system proposes two categories for a staff member to choose between, evaluating shortlist coverage separately from final routing accuracy.
- A retrieval experiment checks whether one designated target item appears within the first ten returned items, clearly naming this target-based hit criterion.
Think of it this way
Think of a shortlist for a quiz answer. You receive credit if the correct answer is somewhere among your allowed guesses. More guesses make the task easier, but they also leave more work for whoever must choose the final answer.
The analogy captures coverage, not certainty. A list containing the answer does not indicate which candidate is correct, and the other entries can still be confusing. The metric alone cannot assess how effectively a person uses the list.
Worked example
A shortlist can look strong while first-choice accuracy is modest
In an invented six-example classification test, the correct labels occupy ranks 1, 2, 4, 1, 3 and 5 in the model's ranked lists.
Top-1 accuracy counts the two first-place hits: 2/6, approximately 33.3%. Top-3 accuracy counts ranks 1, 2, 1 and 3: 4/6, approximately 66.7%. Top-5 accuracy counts all six, giving 100%.
The model's predictions did not change between these calculations. Only the allowed shortlist length changed. Reporting the final number as simply “100% accurate” would hide that four of the six first choices were wrong.
If the system displays only three choices, the top-5 result does not describe the displayed experience. If a downstream reviewer selects among those three, their final success rate needs its own measurement. These ranks are teaching values rather than observed product results.
Illustrative case study
Fictional Cedar Archives evaluates a tool that proposes filing categories. Its top-5 result is much stronger than its top-1 result, so the team considers presenting five suggestions to staff.
A pilot shows that reviewers spend longer comparing similar category names and sometimes choose a plausible but wrong alternative. The team records final decisions and review time as well as whether the correct label was present.
It then evaluates a smaller shortlist and clearer category descriptions. The lesson is that improved candidate coverage can support a workflow, but the operational benefit depends on the subsequent decision. The model metric and the user's completed task remain separate outcomes.
Common misconceptions and mistakes
Do not compare top-1 performance from one model with top-5 performance from another as though both had the same allowance. Always state k.
Top-k accuracy does not assess probability calibration. A correct class ranked second with score 0.49 and one ranked second with score 0.02 both count as hits when k is at least two.
It is also not automatically precision at k or recall at k. Those retrieval measures usually address multiple relevant items and use different denominators. A single-label classification routine should not be silently applied to a multilabel problem without defining the intended evaluation.
Business use
Use the metric when the product actually exposes or consumes a candidate shortlist. Decide k from the review capacity or downstream process before using it to compare models.
Report top-1 alongside the operationally relevant top-k value, and inspect performance for rare or easily confused classes. Document candidate filtering, tie handling and class coverage. If candidates are generated by a separate retrieval stage, evaluate that stage's omissions too: a classifier cannot rank a correct answer that never enters its candidate set. Pair coverage with final task quality and review cost.
People also ask
Does top-1 accuracy equal ordinary accuracy?
In standard single-label classification with the true class as target and consistent tie handling, yes.
Can top-k accuracy decrease when k increases?
Not for the same fixed ranked lists and target labels. A decrease suggests that another part of the evaluation changed or the implementation needs inspection.
Does top-3 accuracy of 90% mean each of the three suggestions is 90% correct?
No. It means the target appeared somewhere in the three suggestions for 90% of evaluated examples.
Check your understanding
A model has top-1 accuracy of 60% and top-3 accuracy of 85% on the same test examples. What does the 25-percentage-point difference represent?
Answer: It is the share of examples whose target is ranked second or third, under the same ranking and tie conventions. It does not describe how often a user will correctly choose among those alternatives.
Related terms
- Accuracy
- Precision at k (precision@k)
- Recall at k (recall@k)
- Probability calibration
- ranked prediction
- shortlist
- hit rate
- precision at k
- recall at k
- mean reciprocal rank
Learn next
Learn ordinary classification accuracy, then calculate top-k values from a few ranked lists. Compare the result with precision at k in a task having multiple relevant items. Finally evaluate the whole shortlist workflow, including candidate generation and the final human or automated selection.
More in Causal inference and experimentation
- Test and Evaluation, Verification and Validation - Test and Evaluation, Verification and Validation, commonly abbreviated TEVV, is a collection of activities that builds evidence about an AI system's...
- Test loss - Test loss is the value of a chosen loss function on a dataset reserved for evaluating a trained and selected model.
- Thurstone model - A Thurstone model represents comparative judgments using latent values disturbed by normally distributed variation.
- Toxicity - In AI evaluation, toxicity refers to abusive, threatening, insulting or otherwise harmful conversational content as defined by a particular assessment scheme.
- Training loss - Training loss is the value of the learning objective measured on examples used to fit a model.
- Treatment-confounder feedback - Treatment-confounder feedback occurs when earlier treatment changes a later variable that both influences subsequent treatment and predicts the outcome.
Sources
Sources: Google Machine Learning Glossary, top-k accuracy: https://developers.google.com/machine-learning/glossary#top-k-accuracy Scikit-learn, top_k_accuracy_score and tie handling: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.top_k_accuracy_score.html Scikit-learn, classification metric definitions: https://scikit-learn.org/stable/modules/model_evaluation.html#top-k-accuracy-score Keras, accuracy metrics: https://keras.io/api/metrics/accuracy_metrics/
Previous: Top-down design Next: Top-k sampling