Evaluating a Classifier Using a Confusion Matrix

Last updated

Problem Setup

Scenario:Evaluate a binary classifier using the outcomes recorded in its confusion matrix.

Given:A confusion matrix containing 40 true positives, 10 false negatives, 15 false positives, and 135 true negatives.

Task:Use the confusion matrix counts to calculate Accuracy, Precision, Recall (Sensitivity), and F1 Score, then interpret the resulting performance measures.

Need a quick refresher? Review Confusion Matrix theory

Confusion Matrix

The matrix compares actual and predicted classes, showing the correct predictions and the two types of classification errors.Positive Class = Fraudulent | Negative Class = Legitimate

Predicted Positive
Predicted Negative
Actual Positive
40
10
Actual Negative
15
135

Calculation Breakdown

1

Accuracy

What proportion of all predictions were correct?

87.5 %
Formula String
TP+TNTP+TN+FP+FN⇒40+13540+135+15+10\frac{TP + TN}{TP + TN + FP + FN} \Rightarrow \frac{40 + 135}{40 + 135 + 15 + 10}
Execution
175200=0.875\frac{175}{200} = 0.875
2

Precision

When the AI predicted 'Yes', how often was it actually right?

72.727 %
Formula String
TPTP+FP⇒4040+15\frac{TP}{TP + FP} \Rightarrow \frac{40}{40 + 15}
Execution
4055=0.727\frac{40}{55} = 0.727
3

Recall (Sensitivity)

Out of all the actual 'Yes' cases, how many did the AI successfully find?

80 %
Formula String
TPTP+FN⇒4040+10\frac{TP}{TP + FN} \Rightarrow \frac{40}{40 + 10}
Execution
4050=0.8\frac{40}{50} = 0.8
4

F1 Score

The harmonic mean. It forces a balance between Precision and Recall.

76.19 %
Formula String
2×Precision×RecallPrecision+Recall⇒2×0.727×0.80.727+0.82 \times \frac{Precision \times Recall}{Precision + Recall} \Rightarrow 2 \times \frac{0.727 \times 0.8}{0.727 + 0.8}
Execution
2×0.5821.527=0.7622 \times \frac{0.582}{1.527} = 0.762

Final Answer

Accuracy:87.5 %

Precision:72.727 %

Recall:80 %

F1 Score:76.19 %

The classifier misses 10 of the 50 fraudulent transactions and incorrectly flags 15 legitimate transactions. Its 87.5% accuracy shows strong overall correctness, but Precision and Recall reveal the mistakes affecting fraud detection that Accuracy alone does not explain.

Exam Takeaway

  • Check class balance before interpreting Accuracy: Accuracy measures overall correctness, but it can look high when one class dominates. A majority-class prediction strategy is a useful baseline for judging whether the result is meaningful.
  • Do not confuse Precision with Recall: Precision uses all predicted positives TP+FPTP + FP as its denominator, while Recall uses all actual positives TP+FNTP + FN. Identify which group the question refers to before choosing the formula.
  • Use F1 Score to assess the balance between Precision and Recall: The harmonic mean is pulled down when either metric is low. F1 is useful when both types of positive-class errors matter, but it does not account for true negatives.