Review Publically — Header (standalone)
How to Read a Confusion Matrix (With Real Examples)
How to Read a Confusion Matrix with real examples

📐 Core ML Concepts · Reference Guide

How to Read a Confusion Matrix (With Real Examples)

During World War II, radar researchers faced a problem that had nothing to do with machine learning, because machine learning did not exist yet. Operators needed to tell real aircraft apart from birds, weather noise, and equipment glitches, and two kinds of mistakes mattered: missing a real threat, and reacting to nothing at all. The framework built to formalize that tradeoff, later called signal detection theory, is the direct ancestor of what data scientists now call a confusion matrix.

That history explains why the confusion matrix exists. A single accuracy number cannot tell you which kind of mistake a model is making, and in most real applications, the two kinds of mistakes are not equally costly. This guide covers exactly how to read one, how to calculate the metrics that matter, how it changes with three or more classes, and where almost everyone trips up the first time. You can follow along with our Confusion Matrix Calculator, which recalculates every metric live as you change the numbers.

by Khalid Hussain updated Sep 02, 2026 🕐 14 min read

The Quick Answer

▶ Direct Answer · Confusion Matrix

A confusion matrix is a table that compares what a model predicted against what actually happened. For two classes, it has four cells: true positives, true negatives, false positives, and false negatives. From those four numbers you can calculate accuracy, precision, recall, and F1 score.

The reason it matters more than accuracy alone: a model can score well on accuracy while completely failing at the one thing you needed it to catch. The confusion matrix is what reveals that failure in seconds.

1950s
decade signal detection theory was formalized
Rooted in WWII radar research
97.8%
accuracy in our worked fraud example below
Sounds great on its own
59.1%
the precision hiding behind that same accuracy number
This is the accuracy paradox

The Four Cells, With a Worked Example

Say a bank runs a fraud-detection model against 500 transactions from last week. Of those, 15 were genuinely fraudulent and 485 were legitimate. The model flags 22 transactions as fraud. Of those 22 flagged transactions, 13 really were fraud and 9 were innocent transactions caught in the net. That means the model missed 2 real fraud cases entirely, letting them through as legitimate, and correctly cleared 476 of the 485 legitimate transactions.

Predicted: FraudPredicted: Legitimate
Actual: Fraud13 (True Positive)2 (False Negative)
Actual: Legitimate9 (False Positive)476 (True Negative)

Each cell answers a different question. True positive: fraud, correctly caught. True negative: legitimate, correctly cleared. False positive: legitimate transaction wrongly flagged, an annoyance for the customer. False negative: real fraud that slipped through, the mistake that actually costs the bank money. Notice that the two error types are not equally costly here, which is exactly why a single accuracy number would hide the real story.

Calculating Precision, Recall, and F1 From the Matrix

Using the fraud example above (TP=13, FP=9, FN=2, TN=476), here is how each metric is built.

1

Accuracy

(TP + TN) / Total = (13 + 476) / 500 = 97.8%. This is the number that looks great and tells you the least.

2

Precision

TP / (TP + FP) = 13 / 22 = 59.1%. Of every transaction the model flagged as fraud, only 59% actually were fraud.

3

Recall

TP / (TP + FN) = 13 / 15 = 86.7%. Of all the real fraud that existed, the model caught 87% of it.

4

F1 Score

2 × (Precision × Recall) / (Precision + Recall) = 70.3%. A single number that balances the two, useful when you need one score rather than a tradeoff.

This is the accuracy paradox in action

A 97.8% accuracy score sounds like a near-perfect model. The precision score of 59.1% tells the real story: almost half of every fraud alert this model generates is a false alarm. Whether that tradeoff is acceptable depends entirely on the cost of investigating a false alarm versus the cost of missing real fraud, which is a business decision, not a math problem.

Confusion Matrix vs. Classification Report

Once you understand how to calculate these metrics by hand, it is worth knowing that most machine learning libraries will do it for you automatically. Scikit-learn's classification_report function takes the same true and predicted labels used to build a confusion matrix and returns precision, recall, F1 score, and support (the number of actual instances) for every class in one readable block of text.

The confusion matrix and the classification report are not competing tools, they answer different questions. The matrix shows you exactly where predictions land, which is essential for spotting patterns like "this model keeps confusing class A with class B specifically." The classification report summarizes the resulting metrics without showing you that structure, and it also adds a "support" column, the actual number of instances of each class, which is useful for spotting whether a strong-looking score is being computed on a tiny, unreliable sample. A reasonable workflow is to check the classification report first for a fast overview, then pull up the full confusion matrix when a specific class's numbers look off and you need to see exactly which other class it is being confused with.

Sensitivity vs. Specificity vs. Recall

This is one of the most common points of confusion, and it is simpler than it looks. Recall and sensitivity are the exact same calculation: TP / (TP + FN). Machine learning literature tends to say recall, while medical and clinical fields tend to say sensitivity, but the formula never changes.

Specificity is a different metric entirely, and it is the one most often confused with precision. Specificity measures the true negative rate: TN / (TN + FP). In the fraud example, specificity is 476 / 485, or 98.1%, meaning the model correctly cleared 98% of legitimate transactions. Precision, by contrast, asks a completely different question about how trustworthy a positive prediction is. Mixing up specificity and precision is one of the most frequent mistakes in this entire topic, largely because both involve the word "true" somewhere in their definition.

Multi-Class Confusion Matrices

Everything above covers binary classification, but most real-world problems involve more than two classes, whether you are sorting support tickets, tagging images, or classifying customer intent. Say you are classifying customer support tickets into three categories: billing, technical, and general. The confusion matrix becomes a 3 by 3 grid instead of 2 by 2, and the same logic extends to however many classes your problem actually has.

Pred: BillingPred: TechnicalPred: General
Actual: Billing4235
Actual: Technical4586
Actual: General7531
The nuance almost everyone misses

In a multi-class matrix, false positives and false negatives are defined per class, not per cell. Take the Billing row: 42 tickets were correctly classified, but 3 were predicted as Technical and 5 as General, meaning Billing has 8 false negatives total (real billing tickets misclassified as something else). Those same 3 and 5 tickets count as false positives for the Technical and General classes respectively, since those classes wrongly claimed tickets that were not really theirs. The diagonal is always where the correct predictions live; everything off the diagonal is a specific, attributable kind of mistake.

Why the Right Metric Depends on the Domain

There is no universally "correct" metric to optimize for every situation. The right choice depends entirely on which type of error costs more in your specific case, which is a judgment call informed by the data, not a rule you can memorize once and reuse everywhere.

DomainCostlier errorMetric to prioritize
Medical screeningFalse negative (missed diagnosis)Recall
Spam filteringFalse positive (real email blocked)Precision
Fraud detectionFalse negative (fraud missed)Recall, with precision as a cost check
Manufacturing defect detectionFalse negative (defective unit shipped)Recall, since a shipped defect can mean a recall or safety incident

A cancer-screening model that misses a real case (false negative) can delay life-saving treatment, so recall usually wins even at the cost of more false alarms and follow-up tests. A spam filter that blocks a legitimate email (false positive) might mean a missed job offer or an important message, so precision usually wins even if a little more spam gets through. A manufacturing quality-control model faces a similar asymmetry to medical screening: missing one defective unit that reaches a customer typically costs far more, in returns, reputation, or safety liability, than the cost of pulling a handful of good units aside for a second inspection. Neither preference is universal. It depends on what each type of mistake actually costs the people affected by it.

Visualizing a Confusion Matrix

Raw counts and visualized heatmaps serve different purposes, and knowing when to use each one matters more than picking a favorite. A heatmap, typically built with a library like Seaborn on top of the raw matrix, makes it fast to spot which off-diagonal cells are darkest, meaning which specific misclassifications happen most often. This is far easier to scan visually than reading a grid of raw numbers, especially once you have five or more classes.

The choice between raw counts and normalized percentages changes what the visualization tells you. Raw counts show absolute error volume, useful when you care about total operational cost, like how many fraud alerts a review team has to process. Normalized percentages, where each row sums to 100%, show relative error rates per class, useful when your classes are imbalanced and a raw count would make a small class's high error rate look visually unimportant next to a large class's low one. As a rule of thumb: use raw counts when volume matters operationally, and normalized percentages when you are comparing how well the model performs across classes of very different sizes.

Try It Yourself

Reading about a confusion matrix and building one from your own numbers are different skills. Our Confusion Matrix Calculator lets you enter your own true positive, true negative, false positive, and false negative counts and see accuracy, precision, recall, and F1 score update instantly, along with a visual breakdown of the matrix itself. It is the fastest way to build an intuition for how changing one cell shifts every metric downstream of it.

📊 Build the Intuition

Confusion Matrix Calculator

Plug in your own numbers and watch every metric recalculate live.

▶  Open the Calculator

Confusion Matrix in Python

If you are working with scikit-learn, generating a confusion matrix and a classification report from real predictions takes only a few lines. The example below mirrors the structure of the fraud example used throughout this guide, with a small array of actual and predicted labels standing in for real transaction data.

from sklearn.metrics import confusion_matrix, classification_report y_true = [1, 0, 1, 1, 0, 1, 0, 0] y_pred = [1, 0, 0, 1, 0, 1, 1, 0] print(confusion_matrix(y_true, y_pred)) print(classification_report(y_true, y_pred))

The first line prints the raw matrix as a NumPy array, rows for actual classes and columns for predicted classes, matching scikit-learn's documented convention. The second line prints precision, recall, F1 score, and support for both classes in one readable block, which is the classification report discussed earlier in this guide. Swapping in your own y_true and y_pred arrays, typically pulled from your model's test-set predictions, is all it takes to run this against a real model.

Common Mistakes When Reading a Confusion Matrix

  • Confusing precision with specificity. Both involve a "true" count in the numerator, but precision is about predicted positives and specificity is about actual negatives. They answer different questions.
  • Assuming rows always mean actual and columns always mean predicted. Most machine learning tools, including scikit-learn, use that convention, but Wikipedia and some statistics textbooks reverse it. Always check the axis labels.
  • Trusting accuracy alone on imbalanced data. If 97% of cases are negative, a model that predicts negative every time scores 97% accuracy while catching zero real positives.
  • Treating false positives and false negatives as fixed per cell in multi-class problems. They are defined per class, and a single misclassified instance is simultaneously a false negative for one class and a false positive for another.
  • Comparing raw counts across models trained or tested on different-sized datasets. A model with 40 false positives out of 10,000 predictions is behaving very differently from one with 40 false positives out of 500, even though the raw number looks identical. Always check the rate, not just the count.

Confusion Matrix Interview Questions

This topic comes up constantly in data science and machine learning interviews, partly because it is easy to test quickly with a short worked example and a follow-up question or two. A few you should be able to answer without hesitation, ideally while narrating your reasoning out loud rather than just stating a final number:

  • Given TP, FP, TN, and FN, calculate precision, recall, and F1. Practice until the formulas are automatic, not memorized. A good interviewer will change the numbers on the spot to see if you actually understand the ratios or just recall a result.
  • Why might you prioritize recall over precision, or the reverse? Answer in terms of which error is more costly in the specific scenario given, not in the abstract. Naming a concrete domain, like the medical and spam examples in this guide, is stronger than a purely theoretical answer.
  • Explain the accuracy paradox. Use a concrete imbalanced-data example, not just the definition. Walking through a quick number, like a 97% accurate model that never predicts the minority class, demonstrates understanding better than reciting the term.
  • How does a confusion matrix change with more than two classes? Be ready to explain that FP and FN become per-class concepts, and that the diagonal always represents correct predictions regardless of how many classes there are.

Our Data Science Interview Quiz includes a full section on classification metrics if you want to practice beyond these four, and our ML Algorithm Picker is a useful next step once you are comfortable evaluating a model, since choosing the right algorithm and evaluating it with a confusion matrix are adjacent skills.

Frequently Asked Questions

What is a confusion matrix in simple terms?

A confusion matrix is a table that compares what a classification model predicted against what actually happened. It breaks predictions into true positives, true negatives, false positives, and false negatives, which lets you see exactly what kind of mistakes a model makes, not just how often it is right.

What is the difference between precision and recall?

Precision measures how many of the model's positive predictions were actually correct (true positives divided by all predicted positives). Recall measures how many of the actual positive cases the model successfully found (true positives divided by all actual positives). A model can have high precision and low recall, or the reverse, depending on how cautious or aggressive it is.

What is the difference between recall and sensitivity?

Recall and sensitivity are the same calculation, true positives divided by all actual positives. Machine learning literature typically says recall, while medical and clinical fields typically say sensitivity, but the formula is identical.

How do you read a multi-class confusion matrix?

A multi-class confusion matrix is an N by N grid, where N is the number of classes. Each row represents the actual class and each column represents the predicted class, though some sources reverse this convention. False positives and false negatives are calculated per class rather than per cell: for any given class, a misclassified instance counts as a false negative for its true class and a false positive for the class it was incorrectly predicted as.

Why can a model have high accuracy but still be bad?

Accuracy treats every correct prediction equally, which breaks down on imbalanced data. If only 3% of cases are actually positive, a model that predicts negative every single time will still be 97% accurate while catching zero real positive cases. This is known as the accuracy paradox, and it is the main reason confusion matrices exist.

Do rows represent actual or predicted values in a confusion matrix?

It depends on the source. Most machine learning contexts, including scikit-learn, use rows for actual classes and columns for predicted classes, but Wikipedia and some statistics textbooks use the opposite convention. Always check the axis labels on any confusion matrix before interpreting it.

What is a good F1 score?

There is no universal threshold, since it depends entirely on the difficulty of the task and the class balance in the data. An F1 score should be judged against a relevant baseline, such as a simple majority-class classifier, rather than against a fixed number like 0.8 or 0.9.

What is the difference between a confusion matrix and a ROC curve?

A confusion matrix reflects performance at one fixed decision threshold. A ROC curve plots the true positive rate against the false positive rate across every possible threshold, showing how the tradeoff between recall and false alarms shifts as a model becomes more or less aggressive. Use a confusion matrix to evaluate a model already deployed at a specific threshold, and a ROC curve to help choose that threshold in the first place.

Conclusion: One Table, Four Numbers, No More Guessing

A confusion matrix is not a complicated tool. Its entire value comes from refusing to collapse a model's behavior into one misleading number. Four cells, correctly read, tell you what accuracy alone will always hide: which specific kind of mistake your model is making, and whether that mistake is one you can actually afford. That is true whether you are debugging a weekend project or defending a production model's behavior to a stakeholder who only trusts the single number on the dashboard.

The definitions and conventions in this guide draw on scikit-learn's official documentation, Wikipedia's canonical entry, and established explainers from GeeksforGeeks, DataCamp, and Dataquest, cross-checked against each other since even the row-and-column convention is not fully standardized across sources. The worked examples and multi-class breakdown are original to this guide. This page was last updated in August 2026.

🎯 Practice What You Just Learned

Data Science Interview Quiz

Classification metrics show up constantly in interviews. Test yourself with the full statistics and machine learning question bank.

▶  Start the Quiz
References · 14 Primary Sources
  1. Wikipedia, Confusion Matrix
  2. scikit-learn, sklearn.metrics.confusion_matrix Documentation
  3. scikit-learn, Evaluate a Classifier with a Confusion Matrix (Examples)
  4. GeeksforGeeks, Understanding the Confusion Matrix in Machine Learning
  5. DataCamp, What is a Confusion Matrix in Machine Learning
  6. Label Your Data, Confusion Matrix: How to Read and Interpret Results
  7. Dataquest, Confusion Matrix in Machine Learning: A Complete Guide
  8. Evidently AI, How to Interpret a Confusion Matrix for a Machine Learning Model
  9. V7 Darwin, Confusion Matrix: How to Use It and Interpret Results
  10. Encord, What is a Confusion Matrix (Machine Learning Glossary)
  11. Medium, The Confusion Matrix Demystified: Beyond Accuracy in Model Evaluation
  12. Statistics Fundamentals, Confusion Matrix Calculator
  13. Medium, All About Confusion Matrix: Preparing for Interview Questions
  14. dsprep.com, Confusion Matrix: Data Science Interview Preparation