# Confusion matrix

> Canonical: https://skillalmanac.com/glossary/confusion-matrix | Last verified: 2026-11-24 | Index status: index-eligible

A confusion matrix tabulates known versus predicted classes. Entries can be counts, weighted counts or normalized proportions. Binary classification has a 2×2 table; single-label multiclass classification has one row and column per included class.

Also called: confusion matrices, error matrix, confusion matrix machine learning, confusion matrix explained.

## In plain language

A confusion matrix is a scorecard that shows how a yes-or-no sorter went wrong, not only how often. Take a spam filter. Some spam is correctly caught, some good mail is wrongly sent to the spam folder, some spam slips through, and some good mail arrives as it should. The table counts each of those four cases separately. That matters because the two kinds of mistake can cost very different things. The limit: the counts depend on the cutoff the filter uses to call something spam, and the table does not tell you which mistake is worse for you. IBM also warns that accuracy on its own can mislead.

## Technical definition

In scikit-learn, C[i,j] records actual class i predicted as class j. With binary label order [negative, positive], the cells are [[TN,FP],[FN,TP]]. Other label orders or tools require their own interpretation. Specify weights and normalization. Multilabel evaluation can use one binary confusion matrix per label or sample.

## How it shows up when you use agents

A confusion matrix appears when you ask a coding agent to evaluate a classifier: a spam filter, a ticket router, or an LLM prompt that labels support messages. The agent prints a small grid of counts. It is the raw material behind the single scores people quote, such as accuracy, precision and recall. Google's accuracy, precision and recall page gives accuracy as correct predictions over all predictions, recall as TP over TP plus FN, and precision as TP over TP plus FP.

What breaks when it is misunderstood. People read the grid with the axes swapped, so false positives and false negatives trade places. They quote one number and skip the grid, which hides the kind of mistake being made. And they compare matrices from different cutoffs as if they came from different models. See [Classification](/glossary/classification) and [Ground truth](/glossary/ground-truth).

Next actions. Ask the agent to print the axis labels with the grid. Say which mistake costs more before you pick a cutoff. Check the test file for leakage with [split-leakage-check](/skills/skill-almanac/split-leakage-check), then compare against the class counts.

## Worked example (illustrative)

For label order [0,1], with 1 positive, the synthetic matrix [[981,9],[4,6]] has actual classes in rows and predictions in columns. It represents TN=981, FP=9, FN=4 and TP=6. Reversing label order or transposing axes changes which cell means which. This matrix was checked with scikit-learn on constructed labels; it is not a measured result for any catalog skill.

## Common confusions

- **False positive versus false negative.** Google's example: a false positive is a not-spam email misclassified as spam, and a false negative is a spam email misclassified as not-spam.
- **Rows versus columns.** In scikit-learn, rows are the known labels and columns are the predicted labels. Do not assume another tool uses the same layout.
- **Confusion matrix versus accuracy.** Accuracy is one number computed from the matrix. IBM warns it can be misleading on its own.
- **Counts versus rates.** The raw cells are counts. The normalize option in scikit-learn turns them into proportions of rows, columns or the total, which answer different questions.

## Worked examples in this catalogue

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A check of train, validation and test files for duplicates, shared groups, time and label leakage, printed as JSON.

Why it exercises the concept: Check the test data for leakage before interpreting the confusion matrix. This skill checks the data rather than calculating the matrix.

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.

Why it exercises the concept: When an LLM feature sorts items into labels, an eval set with known labels is what a confusion matrix is computed from. The skill checks for imbalance, which affects how the counts should be read. It does not compute the matrix.

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A fixed exploratory-analysis procedure and CSV profiler that keeps findings descriptive, evidenced and caveated.

Why it exercises the concept: Profiling a labelled table shows how many rows are in each class before you read any counts. This skill profiles data; it does not train or score a classifier.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Claude Code's overview page describes it as an agentic coding tool that reads your codebase, edits files, runs commands, and integrates with your development tools.

Why it exercises the concept: A coding agent can run scikit-learn's confusion_matrix on a small table of true and predicted labels, so you can check which axis holds which label for yourself.

## Related terms

- [Classification](https://skillalmanac.com/glossary/classification.md)
- [Ground truth](https://skillalmanac.com/glossary/ground-truth.md)
- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Overfitting](https://skillalmanac.com/glossary/overfitting.md)
- [Logistic regression](https://skillalmanac.com/glossary/logistic-regression.md)

## Sources

- [Classification: Accuracy, recall, precision and related metrics](https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall), Google for Developers (Machine Learning Crash Course) (accessed 2026-11-24)
- [Classification: Thresholds and the confusion matrix](https://developers.google.com/machine-learning/crash-course/classification/thresholding), Google for Developers (Machine Learning Crash Course) (accessed 2026-11-24)
- [sklearn.metrics.confusion_matrix](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html), scikit-learn (accessed 2026-11-24)
- [What is a confusion matrix?](https://www.ibm.com/think/topics/confusion-matrix), IBM (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
