esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Let’s talk

I’ll build the agent for it.

What Is a Confusion Matrix?

What a confusion matrix is, its four boxes, and why it shows the mistakes that a single accuracy score hides, explained simply for your AI interview.

In short

A confusion matrix is a table that compares a yes-or-no model's answers with what was really true, in four boxes: true positives, false positives, false negatives and true negatives. Scores like accuracy, recall and precision are all worked out from those four counts.

10 min readBeginnerCommon · estimateFacts checked 27 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

A confusion matrix is a table that counts every answer a yes-or-no model gives, against what was really true. It has four boxes: true positives, false positives, false negatives and true negatives. Accuracy hides the trouble. For a bank's fraud screen, the table shows how much real fraud gets missed and how many good customers get blocked. So I read the table first, then the scores.

What is a confusion matrix, in plain words?

A confusion matrix is a table for a model that answers yes or no, such as fraud or fine, or spam or not spam. In the tables here, each row is what really happened, and each column is what the model said. Every case lands in exactly one box, so the table shows where the model gets things mixed up. With more than two answers, the table grows to one row and one column per answer, and the right calls sit on its diagonal.

Think of a fraud analyst at a bank who checks last night's alarms. Some alarms were real fraud and some were a customer buying something unusual. The analyst keeps a tally of right and wrong calls. A card-fraud screen does the same job on every payment, and its tally is a confusion matrix.

Key words

Ground truth
What really happened, as confirmed later by a record or a person.
Positive class
The case you are looking for, such as fraud. It is called positive even though it is bad news.
Binary classifier
A model that sorts each item into one of two groups.
Imbalanced data
One group is rare, such as about 1.2% of card payments (roughly 1 in 83).

What are the four boxes?

A two-answer model gives four possible results for each case, so the table has four boxes. Two boxes are right calls and two are mistakes. Read each name as two words. The first says whether the call was right (true) or wrong (false). The second says what the model said (positive or negative).

Four boxes for a fraud screen

Card payments: 10,000

every payment the screen read

What really happened

Real fraud: 120

payments the attacker made

Real payments: 9,880

genuine customer payments

The four outcomes

Caught: 90

fraud stopped (true positive)

Missed: 30

fraud let through (false negative)

Wrongly blocked: 180

good payment stopped (false positive)

Let through: 9,700

good payment passes (true negative)

  1. 1120 of the payments were real fraud.
  2. 2The other 9,880 were genuine customer payments.
  3. 3The screen blocks 90 of the 120 real frauds.
  4. 4The other 30 frauds get through, and money is lost.
  5. 5It also blocks 180 good payments, and those customers get annoyed.
  6. 6The other 9,700 good payments pass, as they should.
Each of the 10,000 made-up card payments lands in one of four outcome boxes. The two green boxes are right calls, and the two orange outcome boxes (missed and wrongly blocked) are mistakes. The count sits in each box, so you can add them up.
  • True positive (TP)

    The model said fraud, and it was fraud. The fraud is stopped.

  • False positive (FP)

    The model said fraud, but the payment was genuine. A good customer is blocked.

  • False negative (FN)

    The model said fine, but it was fraud. The money leaves the account.

  • True negative (TN)

    The model said fine, and it was genuine. The payment goes through.

How do the four boxes become scores?

Take a bank's card-fraud screen that checks 10,000 card payments (made-up numbers). 120 of them are real fraud, and the other 9,880 are genuine. The four boxes give three common scores.

  1. 1

    Read the table

    90 frauds caught, 30 missed, 180 good payments blocked, 9,700 let through.

  2. 2

    Accuracy: all right calls

    (90 + 9,700) / 10,000 = 97.9%. It looks excellent, and that is the trap.

  3. 3

    Recall: share of fraud caught

    90 / 120 = 75%. One fraud in four gets through.

  4. 4

    Precision: share of blocks that were right

    90 / (90 + 180) = 33%. Two out of three blocks hit a good customer.

Which score matters depends on the cost of each mistake. Accuracy hides both costs, because 9,700 easy passes make the total look good. On rare cases, a model can score high by always giving the common answer.

  • “For heavily imbalanced datasets, where one class appears very rarely, say 1% of the time, a model that predicts negative 100% of the time would score 99% on accuracy, despite being useless.”

    Google Machine Learning Crash Course

Here is the same table and the scores in plain Python, with made-up numbers. It uses only the standard library.

Python
# A bank's card-fraud screen checks 10,000 card payments (made-up numbers).
# Rows: what really happened. Columns: what the screen said.
TP, FN = 90, 30     # 120 real frauds: 90 caught, 30 missed
FP, TN = 180, 9700  # 9,880 genuine payments: 180 wrongly blocked, 9,700 let through

total = TP + FN + FP + TN
print(f"{'':<14}{'said fraud':>12}{'said fine':>12}")
print(f"{'really fraud':<14}{TP:>12}{FN:>12}")
print(f"{'really fine':<14}{FP:>12}{TN:>12}")
print(f"accuracy  {(TP + TN) / total:.1%}")
print(f"recall    {TP / (TP + FN):.1%}   (share of real fraud caught)")
print(f"precision {TP / (TP + FP):.1%}   (share of blocks that were fraud)")
print(f"always 'fine' gets {(TN + FP) / total:.1%} accuracy and catches 0% of fraud")

Output

                said fraud   said fine
really fraud            90          30
really fine            180        9700
accuracy  97.9%
recall    75.0%   (share of real fraud caught)
precision 33.3%   (share of blocks that were fraud)
always 'fine' gets 98.8% accuracy and catches 0% of fraud

Which way round is the table?

Not every tool draws the table the same way. Google's course puts the real answer in the columns and the model's answer in the rows. scikit-learn, a Python machine learning library, does it the other way: real labels in the rows and predictions in the columns. The four counts are the same, only moved.

  • “if you lay out the ground truth as columns and the model's prediction as rows, the following table, called a confusion matrix, is the result”

    Google Machine Learning Crash Course

  • “Confusion matrix whose i-th row and j-th column entry indicates the number of samples with true label being i-th class and predicted label being j-th class.”

    scikit-learn

By default scikit-learn sorts the labels, so in its binary layout the top left box holds true negatives and the bottom right box holds true positives. Our Python table lists fraud first, so there the top left box holds true positives.

Tip

Check the labels before you trust a number. If you read the rows and columns the wrong way round, you divide by the wrong total and get a score that looks right but is not.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: a table of right and wrong calls, against what really happened.
  • The four boxes, named in plain words.
  • How accuracy, recall and precision come from the same four counts.
  • Why accuracy misleads on rare cases, with a number.
  • Layouts differ between tools, so read the labels first.
  • The cost of each mistake decides which score to trust.

Common traps

  • Trap"A high accuracy means the model is good."

    BetterCheck the rare class first. A model that always gives the common answer can look accurate.

  • Trap"The top left box is always the right answer."

    BetterIt depends on the tool. Read the labels before you read the box.

  • Trap"A false positive and a false negative are the same mistake."

    BetterA missed fraud costs money, and a blocked customer loses trust. Which one costs more decides the score.

Can you read the table?

Find the costly miss

Which box is the costly miss, where real fraud gets through?

Quick check

A fraud screen scores 97.9% accuracy on data where only 1.2% of payments are fraud. What should you check next?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q420Precision, recall and F1?10 min
  2. Q421ROC-AUC vs PR-AUC?11 min
  3. Q425How do you handle class imbalance?12 min
  4. Q413Overfitting vs underfitting?10 min
  5. Q253Exact match, accuracy and F1 for LLM tasks?12 min
  6. Q278How do you evaluate an LLM classifier (confusion matrix)?12 min

Learn it in depth

Last updated on 27 November 2026

Scoring a model that makes an important call?

I design and build AI products and agents, including the interface and the system behind it. Book a short call and tell me what a wrong answer costs you.