Confusion Matrix — Make-or-Break Guide (With Apple/Orange Intuition)
Are you confused with Confusion Matrix? No worries! By the end of this blog, you’ll be super confident about what it is, how to read it, and how to use Precision, Recall, F1-score, Macro & Weighted averages like a pro.
Problem Statement
Social Network Ads dataset: build a model to predict whether a person will purchase after clicking an ad (Yes/No). Assume the model is trained; now the crucial part is validation. That’s where the Confusion Matrix comes in.
Model Used & Report
For explanation, we used a Random Forest. Below is the confusion matrix and classification report screenshot.
What is a Confusion Matrix?
It compares Actual labels vs Predicted labels and tells you where the model is correct or wrong.
Interpretation (Apple/Orange)
- True Apple (TA): Model correctly says Apple.
- False Apple (FA): Model says Apple but it was Orange.
- False Orange (FO): Model says Orange but it was Apple.
- True Orange (TO): Model correctly says Orange.
Numbers in this example
Example counts from your narration (Test Set ≈ 134):
- Correct Apple (TA) = 78
- Correct Orange (TO) = 43
- Total Apple in test ≈ 85
- Misclassifications are the remaining cells (fill from your report)
Key Evaluation Metrics
1) Accuracy
(TA + TO) / (TA + TO + FA + FO)Meaning: Overall how many predictions are correct. In our example: (78 + 43) / 134.
2) Recall (Sensitivity)
Recall(Apple) = TA / (TA + FO) • Recall(Orange) = TO / (TO + FA)Use when: Dataset is imbalanced; we care about catching all positives in each class.
78 / 85 ≈ 0.92 (92%) — model recovers most Apples.
3) Precision
Precision(Apple) = TA / (TA + FA) • Precision(Orange) = TO / (TO + FO)Meaning: Of all predicted as a class, how many were actually that class?
Example: Precision(Apple) = 78 / (78 + 6) ≈ 0.93 (93%).
4) F1-Score
F1 = 2 × (Precision × Recall) / (Precision + Recall)Why: Balances Precision & Recall; great for imbalanced data.
5) Macro Average
Average(metric over classes) — treats each class equally.6) Weighted Average
Average(metric weighted by class support) — accounts for class proportions.Upcoming posts: What is AI? • What is ML?
If you found this useful, drop a comment & share with a friend learning ML!
Join our next Free Live Session