Introduction to Classification Models
Evaluating a classification model involves calculating its classification accuracy.
A Batch of Spam Predictions
A classification model looks at an input and assigns it to a category, such as spam or not spam, or cat or dog. Once a model has made a batch of these assignments, the obvious question is how good those assignments were. Evaluating a classification model means answering that question with a number. This article focuses on that number, called classification accuracy.
What do you think happens?
A model makes 5 predictions and 3 of them match the true labels. What is its classification accuracy?
Reveal answer
60%, which is the fraction 3/5 written as a percentage
Accuracy counts the correct predictions, divides by the total number of predictions, and reports the result. Here 3 correct predictions out of 5 total gives $\frac{3}{5} = 0.6$, and 0.6 expressed as a percentage is 60%.
Matching Each Prediction to Its True Label
Accuracy is about correctness. Each prediction either matches the true label or it does not. To find out which, you line up the predictions with the true labels position by position: the first prediction is compared with the first true label, the second with the second, and so on. A pair that agrees is a match, and a pair that disagrees is not.
Matching Five Email Predictions
A spam filter labels five emails. The true labels and the model's predictions are: Email 1 true spam, predicted spam; Email 2 true not spam, predicted spam; Email 3 true spam, predicted spam; Email 4 true not spam, predicted not spam; Email 5 true spam, predicted not spam. What is the classification accuracy?
- 1Pair each prediction with its true label
Compare the two labels at each position. Email 1 agrees, Email 2 disagrees, Email 3 agrees, Email 4 agrees, Email 5 disagrees.
- 2Count the correct predictions
Emails 1, 3, and 4 are matches, so there are 3 correct predictions.
- 3Count the total predictions
There are 5 emails, so there are 5 predictions in total.
- 4Divide correct by total
$\frac{3}{5} = 0.6$. The accuracy as a fraction is 3/5.
- 5Convert to a percentage
Multiply the fraction by 100 to get $0.6 \times 100 = 60\%$.
The classification accuracy is 3/5, which is 60%.
Defining Classification Accuracy
Classification accuracy is the fraction or percentage of correct predictions a model makes. It reports how often the model's predictions matched the true labels, across all of the predictions being evaluated. A higher accuracy means a larger share of the predictions were correct, and a lower accuracy means a smaller share were.
- 1Count the correct predictions: the predictions that match their true labels.
- 2Count the total predictions: every prediction the model made in the batch being evaluated.
- 3Divide the first count by the second. The result is the accuracy as a fraction.
- 4Multiply the fraction by 100 to express the accuracy as a percentage: $\text{accuracy (\%)} = \frac{\text{correct}}{\text{total}} \times 100$.
Accuracy is a single number that answers the question of how good a batch of assignments was, and it is built from only two counts: how many predictions were correct and how many predictions there were altogether.
Splitting Predictions Into Correct and Incorrect
Every prediction falls into exactly one of two groups: correct or incorrect. The correct count and the incorrect count together add up to the total number of predictions. That addition is a useful check. In the spam example, 3 correct predictions and 2 incorrect predictions make 5 in total, which is the denominator used in the accuracy calculation.
Fraction Versus Percentage Forms
The same accuracy can be written two ways. The fraction form shows the counts directly, so a reader can see how many predictions were correct out of how many were made. The percentage form rescales the same value to a share out of 100, which is convenient for comparison. The two forms describe the same accuracy, but they are not interchangeable labels for different quantities, so it helps to keep them clearly distinguished when you report them.
| Correct | Total | Fraction form | Decimal value | Percentage form |
|---|---|---|---|---|
| 3 | 5 | $\frac{3}{5}$ | 0.6 | 60% |
| 4 | 5 | $\frac{4}{5}$ | 0.8 | 80% |
| 9 | 10 | $\frac{9}{10}$ | 0.9 | 90% |
| 1 | 4 | $\frac{1}{4}$ | 0.25 | 25% |
Each row uses the same two-step method: divide correct by total, then multiply by 100 for the percentage.
Mistakes When Reading Accuracy
Common mistake Reporting a percentage without the total it came from
What it looks likeSaying a model has 80% accuracy with no mention of how many predictions were evaluated.
Why it failsThe source advises always reporting accuracy with its total in view. Without the total, a reader cannot tell whether 80% came from 4 predictions or from 400.
Do this insteadReport the fraction together with the percentage, such as 4/5 (80%), so the total is visible.
Common mistake Dividing by the number of correct predictions instead of the total
What it looks likeComputing 3 divided by 3 when only 3 of 5 predictions were correct.
Why it failsAccuracy is the fraction of all predictions that were correct, so the denominator must be the total count, not the correct count.
Do this insteadDivide the correct count by the total count: $\frac{3}{5} = 0.6$.
Common mistake Mixing up the fraction form and the percentage form
What it looks likeWriting 60 as the accuracy when the fraction is 3/5, or writing 0.6% when the percentage is 60%.
Why it failsThe fraction and the percentage express the same accuracy on different scales, and treating one as the other changes the reported value by a factor of 100.
Do this insteadKeep the two forms distinct: 0.6 as a fraction equals 60% as a percentage.
Common mistake Counting only the correct predictions and forgetting the incorrect ones, which makes the total smaller than the number of predictions actually made.
Practice Calculating Accuracy
A model labels 10 emails and 8 of its predictions match the true labels. Compute the classification accuracy as a fraction and as a percentage, and state the total you used.
Hints
- Count the correct predictions first: 8 of them.
- The total is the number of predictions, not the number of correct ones: 10.
- Write the fraction as $\frac{8}{10}$, then multiply the simplified value by 100 for the percentage.
Key Takeaways
- Classification accuracy is the fraction or percentage of correct predictions a model makes, measured against the true labels.
- To calculate it, count the correct predictions, count the total predictions, and divide the first count by the second.
- Predictions are matched to true labels position by position, and each prediction is either a match or not.
- Always report accuracy with its total in view, and keep the fraction and percentage forms clearly distinguished.