# What is the definition of Top-n accuracy?

I'm reading a Scientific paper on image classification. In the experimental results they speak of top-1 and top-5 accuracy but i've never heard of the term, nor can find it using google.

Can someone give me a definition or point me somewhere? :)

## 2 Answers

In top-5 accuracy you give yourself credit for having the right answer if the right answer appears in your top five guesses.

I found this explanation by one Nathan Yan on Quora

Top-N accuracy means that the correct class gets to be in the Top-N probabilities for it to count as “correct”. As an example, suppose I have a data set of images

• Dog
• Cat
• Dog
• Bird
• Cat
• Cat
• Mouse
• Penguin

For each of these, the model will predict a class, which will appear next to the correct class in quotations

• Dog “Dog”
• Cat “Bird”
• Dog “Dog”
• Bird “Bird”
• Cat “Cat”
• Cat “Cat”
• Mouse “Penguin”
• Penguin “Dog”

The Top-1 accuracy for this is (5 correct out of 8), 62.5%. Now suppose I also list out the rest of the classes the model predicted, in descending order of their probabilities (the further right the class appears, the less likely the model thinks the image is tat class)

- Dog “Dog, Cat, Bird, Mouse, Penguin”
- Cat “Bird, Mouse, Cat, Penguin, Dog”
- Dog “Dog, Cat, Bird, Penguin, Mouse”
- Bird “Bird, Cat, Mouse, Penguin, Dog”
- Cat “Cat, Bird, Mouse, Dog, Penguin”
- Cat “Cat, Mouse, Dog, Penguin, Bird”
- Mouse “Penguin, Mouse, Cat, Dog, Bird”
- Penguin “Dog, Mouse, Penguin, Cat, Bird”


If we take the top-3 accuracy for this, the correct class only needs to be in the top three predicted classes to count. As a result, despite the model not perfectly getting every problem, its top-3 accuracy is 100%!