How to use this calculator
Calculate the share of evaluated examples whose correct class appears among the model's top k predictions.
- Enter Examples correct within top k, Total evaluated examples, Top-k cutoff k. Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
How this calculation works
Top-k accuracy counts a prediction as correct when the true class is present anywhere in the k highest-scored classes. It is useful when several ranked alternatives are acceptable for review, and it differs from top-1 accuracy when k is greater than one.
Inputs and units
correct— Examples correct within top k- Count examples where the true class appears among the first k ranked predictions.
evaluated— Total evaluated examples- Use the number of labeled examples included in the same evaluation.
k— Top-k cutoff k- Enter the number of highest-scored classes treated as candidate predictions.
Formula
Top-k accuracy (%) = examples with the true class in the top k ÷ evaluated examples × 100.
Method
Enter the number of examples whose true class appears within the first k ranked predictions and the total evaluated examples. The value of k documents the ranking cutoff; the numerator must already reflect that cutoff.
Worked example
If the correct class appears in the top five for 78 of 100 examples, top-5 accuracy is 78 ÷ 100 × 100 = 78%.
Assumptions and limits
This aggregate count does not inspect prediction scores or class ordering. Compare values only when the label set, evaluation sample, and k definition are consistent.
Frequently asked questions
What does k mean?
It is the number of highest-ranked class scores checked for inclusion of the true class.
Is top-1 accuracy the usual accuracy?
For single-label classification, top-1 accuracy checks only the highest-scored class; setting k to 1 gives that case.
Can top-k accuracy be compared across different k values?
Use caution: a larger k gives more opportunities to include the true class, so report the cutoff with the score.
How do I use the Top-k accuracy calculator?
Enter Examples correct within top k, Total evaluated examples, Top-k cutoff k. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Top-k accuracy?
If the correct class appears in the top five for 78 of 100 examples, top-5 accuracy is 78 ÷ 100 × 100 = 78%.
Reference: scikit-learn API reference. See our calculation methodology.