Top-k Accuracy Calculator
Paste a table of ranked predictions — or raw class scores — and read off top-1, top-5, and everything in between. Reports the exact hit count, a full top-1…top-k ladder, and the samples missed at k. Mirrors scikit-learn's top_k_accuracy_score. No signup, no upload.
How it works
Top-k accuracyanswers one question about a classifier: how often is the correct label among the model's k highest-scoring guesses? A single sample counts as a hit at cutoff k exactly when its true label appears in the top k predictions. This is the definition scikit-learn implements in top_k_accuracy_score, and top-1 accuracy is identical to ordinary accuracy_score.
The metric became standard through the ImageNet Large Scale Visual Recognition Challenge (Russakovsky et al., 2015), where classifiers pick among 1,000 visually similar classes. Judging only the single top guess is harsh when a Siberian husky is labelled an Eskimo dog, so the challenge reported top-5 accuracyalongside top-1 — the number you still see quoted as “top-1 / top-5” on model cards today.
The calculation this tool runs is:
- Rank each sample. In ranked-labels mode the row is already in score order. In score-matrix mode the
(class, score)pairs are sorted by score descending — stably, so tied scores keep header order, matching scikit-learn's argsort selection. - Find the rank of the true label — the 1-based position where it first appears, or infinity if it never does.
- Score at k. The sample is a hit at k iff its rank ≤ k:
top-k accuracy = (samples with rank ≤ k) / (total samples)The tool also exposes the raw hit count, which is what scikit-learn returns undernormalize=False. - Build the ladder.Because each sample's rank is computed once, accuracy at every cutoff from 1 to your chosen k is a single pass: accuracy@k′ is the fraction of samples with rank ≤ k′. The ladder is always monotonic non-decreasing — a wider top-k can only capture more true labels — so a drop would signal a parsing error and is flagged.
Two independent derivations back the result. The ladder counts hits from each sample's precomputed rank; a separate check re-counts them with a direct membership scan over the top-k slice. The “scikit-learn verified” badge lights only when the two agree on every rung. All of this runs client-side — your predictions never leave the browser.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — sklearn.metrics.top_k_accuracy_score (reference implementation and formal definition)
- scikit-learn User Guide §3.3 — Top-k accuracy score (prose definition; top-1 equals accuracy_score)
- Russakovsky et al. — ImageNet Large Scale Visual Recognition Challenge (IJCV 2015), §4.1: origin of top-1 / top-5
The definition on this page was last cross-checked against the scikit-learn documentation on 2026-07-13. This is a fixed mathematical definition that does not change over time; the result is verified by computing hits two independent ways and confirming they agree.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.