A confusion matrix is a table used to evaluate classification models. It compares the model's predictions with the true labels.
A Confusion Matrix Shows
Correct positive predictions
Incorrect positive predictions
Correct negative predictions
Incorrect negative predictions
It helps explain what kinds of mistakes a model is making.
Why Confusion Matrices Matter
Accuracy only tells us the percentage of correct predictions. A confusion matrix gives more detail by showing the type of each correct and incorrect prediction.
A Confusion Matrix Helps Answer
How many positives were correctly found?
How many negatives were correctly found?
How many false alarms happened?
How many positive cases were missed?
Binary Classification
A binary classification problem has two possible classes. Confusion matrices are commonly used for binary classification.
Binary Classification Examples
Spam or Not Spam
Fraud or Not Fraud
Disease or No Disease
Pass or Fail
Positive or Negative
Positive and Negative Classes
In binary classification, one class is usually called positive and the other is called negative. The meaning depends on the problem.
Disease Detection
Positive: Disease Present
Negative: No Disease
Spam Detection
Positive: Spam
Negative: Not Spam
Prediction vs Actual Label
A confusion matrix compares what the model predicted with the correct answer from the dataset.
Example
Prediction: Spam
Actual Label: Not Spam
Result: Incorrect prediction
The confusion matrix shows what type of incorrect prediction it is.
The Four Parts of a Confusion Matrix
A binary confusion matrix contains four main values.
The Four Parts
True Positive — Model predicts positive, actual label is positive
False Positive — Model predicts positive, actual label is negative
True Negative — Model predicts negative, actual label is negative
False Negative — Model predicts negative, actual label is positive
True Positives
A true positive happens when the model correctly predicts the positive class. The model found a positive case correctly.
Disease Detection Example
Prediction: Disease Present
Actual Label: Disease Present
Result: True Positive
False Positives
A false positive happens when the model predicts positive, but the actual label is negative. The model raised a false alarm.
Disease Detection Example
Prediction: Disease Present
Actual Label: No Disease
Result: False Positive
True Negatives
A true negative happens when the model correctly predicts the negative class. The model correctly identified a negative case.
Disease Detection Example
Prediction: No Disease
Actual Label: No Disease
Result: True Negative
False Negatives
A false negative happens when the model predicts negative, but the actual label is positive. The model missed a positive case.
Disease Detection Example
Prediction: No Disease
Actual Label: Disease Present
Result: False Negative
Confusion Matrix Layout
A common confusion matrix layout uses actual labels as rows and predicted labels as columns. Always check the labels since tools may display them differently.
Layout
Actual Positive + Predicted Positive = True Positive
Actual Positive + Predicted Negative = False Negative
Actual Negative + Predicted Positive = False Positive
Actual Negative + Predicted Negative = True Negative
Confusion Matrix Example
Imagine a disease detection model tested on 100 patients.
Helps balance catching fraud with avoiding unnecessary blocked transactions.
Confusion Matrix and Imbalanced Data
A confusion matrix is especially helpful with imbalanced data because it reveals mistakes that accuracy can hide.
Fraud Dataset
Normal Transactions: 990
Fraud Transactions: 10
Model: Predicts everything as normal
Accuracy: 99%
True Positives: 0, False Negatives: 10
The model missed every fraud case, despite 99% accuracy.
Confusion Matrix for Multi-Class Classification
Confusion matrices can also be used for multi-class classification. They show which classes were confused with each other.
Example Classes: Cat, Dog, Bird
Actual Cat predicted as Dog
Actual Bird predicted as Cat
Actual Dog predicted as Dog correctly
Helps identify which classes are hardest for the model to separate.
Reading a Multi-Class Confusion Matrix
In a multi-class confusion matrix, correct predictions usually appear on the diagonal, while incorrect predictions appear off the diagonal.
Reading the Matrix
Rows: Actual classes
Columns: Predicted classes
Diagonal: Correct predictions
Off-diagonal: Incorrect predictions
Example: If many cats are predicted as dogs, the model may struggle to separate cats from dogs.
Common Mistakes
Common Mistakes
Confusing false positives and false negatives
Looking only at accuracy
Ignoring the cost of different errors
Not checking class imbalance
Misreading rows and columns
Assuming all mistakes are equally serious
Ignoring precision and recall
Not evaluating performance across groups
A confusion matrix is useful only when it is interpreted carefully.
Summary
Key Takeaways
A confusion matrix organizes classification results.
It compares predicted labels with actual labels.
True positives are correctly predicted positives.
False positives are incorrectly predicted positives.
True negatives are correctly predicted negatives.
False negatives are incorrectly predicted negatives.
Accuracy, precision, recall, and F1 score can be calculated from a confusion matrix.
Confusion matrices reveal mistakes that accuracy alone can hide.
False positives and false negatives have different real-world meanings.
Practice Prompt
A disease detection model has 50 true positives, 20 false positives, 80 true negatives, and 10 false negatives.
Identify what each number means. Then calculate accuracy, precision, and recall from the confusion matrix.
Need Help?
Ask the AI if you need help understanding true positives, false positives, true negatives, false negatives, accuracy, precision, recall, or how to read a confusion matrix.