Short Definition
A confusion matrix summarizes prediction outcomes by comparing predicted and true labels.
Definition
A confusion matrix is a table that counts how often a model’s predictions fall into each category of correct and incorrect outcomes. In binary classification, it consists of true positives, false positives, true negatives, and false negatives.
The confusion matrix forms the foundation for many evaluation metrics.
Why It Matters
Aggregate metrics such as accuracy can hide important failure patterns. The confusion matrix exposes exactly how a model is making mistakes.
It allows practitioners to diagnose bias toward certain classes and understand trade-offs between different error types.
How It Works (Conceptually)
- Rows represent true labels
- Columns represent predicted labels
- Each cell counts prediction outcomes
- Metrics are derived from these counts
The confusion matrix provides a complete error breakdown.
Binary Classification Structure
Predicted Positive Predicted Negative
Actual Positive True Positive False Negative
Actual Negative False Positive True Negative
Minimal Python Example
confusion = {"TP": tp,"FP": fp,"FN": fn,"TN": tn}
Common Pitfalls
- Interpreting metrics without inspecting the matrix
- Ignoring class imbalance effects
- Assuming symmetric error costs
- Using confusion matrices without context