Concepts / Introduction to Classification Models

Introduction to Classification Models

Evaluating a classification model involves calculating its classification accuracy.

  • Programming

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?

  • 20%

  • 40%

  • 60%

  • 80%

Reveal answer
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.

Email 1true spam, predicted spamEmail 2true not spam, predictedspamEmail 3true spam, predicted spamEmail 4true not spam, predictednot spamEmail 5true spam, predicted notspam
Each position holds one email. Comparing the prediction with the true label at the same position shows which pairs match. Positions 1, 3, and 4 agree; positions 2 and 5 do not.
Worked example

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?

  1. 1
    Pair 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.

  2. 2
    Count the correct predictions

    Emails 1, 3, and 4 are matches, so there are 3 correct predictions.

  3. 3
    Count the total predictions

    There are 5 emails, so there are 5 predictions in total.

  4. 4
    Divide correct by total

    $\frac{3}{5} = 0.6$. The accuracy as a fraction is 3/5.

  5. 5
    Convert to a percentage

    Multiply the fraction by 100 to get $0.6 \times 100 = 60\%$.

Result

The classification accuracy is 3/5, which is 60%.

Defining Classification Accuracy

Definition

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.

Formula, step by step
  1. 1
    Count the correct predictions: the predictions that match their true labels.
  2. 2
    Count the total predictions: every prediction the model made in the batch being evaluated.
  3. 3
    Divide the first count by the second. The result is the accuracy as a fraction.
  4. 4
    Multiply the fraction by 100 to express the accuracy as a percentage: $\text{accuracy (\%)} = \frac{\text{correct}}{\text{total}} \times 100$.
Key point

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.

Email 1correctEmail 2incorrect5 total predictions3 correct + 2 incorrectEmail 3correctEmail 5incorrectEmail 4correctcountedcounted
The five predictions split into a correct group and an incorrect group. The sizes of the two groups sum to the total used as the denominator.

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.

CorrectTotalFraction formDecimal valuePercentage form
35$\frac{3}{5}$0.660%
45$\frac{4}{5}$0.880%
910$\frac{9}{10}$0.990%
14$\frac{1}{4}$0.2525%

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 like

    Saying a model has 80% accuracy with no mention of how many predictions were evaluated.

    Why it fails

    The 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 instead

    Report 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 like

    Computing 3 divided by 3 when only 3 of 5 predictions were correct.

    Why it fails

    Accuracy is the fraction of all predictions that were correct, so the denominator must be the total count, not the correct count.

    Do this instead

    Divide 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 like

    Writing 60 as the accuracy when the fraction is 3/5, or writing 0.6% when the percentage is 60%.

    Why it fails

    The 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 instead

    Keep 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

EASY

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.

Related concepts

More concepts starting with I