ApiaryActiveLive
Try: pause · settings · learn · wipe
← Community / Reading Room
CM
craft · 26 min read

Confusion Matrix: Seeing Which Mistakes a Classifier Makes, Not Just How Many

A confusion matrix is a table that counts every combination of true class and predicted class in a test set. If a document classifier sorts files into…

Accuracy tells you how often a classifier is wrong. A confusion matrix tells you how it is wrong, which is what you need to decide whether it is safe to use and what to fix.

AI disclosure. This longread was drafted by AI (Claude, from an earlier Grok Bot draft) for Apiary. It has not been reviewed or verified by the founder. Sources were opened and read on 26 November 2026; provider documentation changes often, so dated details are marked. Worked examples are hypothetical.

A confusion matrix is a table that counts every combination of true class and predicted class in a test set. If a document classifier sorts files into invoice, receipt and contract, its confusion matrix has nine cells: true invoices predicted as invoices, true invoices predicted as receipts, true invoices predicted as contracts, and so on for every pairing. The cells on the diagonal are correct predictions. Every cell off the diagonal is a specific kind of mistake.

Accuracy is a single number: the share of all predictions that were right. It is the sum of the diagonal divided by the total. That compression throws away almost everything a person deciding whether to trust a classifier needs to know: which classes are being confused with which, in which direction the confusion runs, whether a high score comes mostly from an easy and common class, and whether the rare, costly class is being handled at all. Two classifiers can have identical accuracy and completely different mistakes (section 5 shows one pair). Only the matrix shows the difference.

This page explains how a confusion matrix is laid out (and why you must read its axis labels every time), which metrics are calculated from it, how normalization turns counts into per-class recall and precision, how imbalance and decision thresholds change it, why label errors in the test set show up as model confusions, and how to read and report one. It also corrects three errors in this page's earlier version, listed in section 16.

1. What a confusion matrix is

The scikit-learn documentation gives the standard definition: "By definition a confusion matrix C is such that C(i, j) is equal to the number of observations known to be in group i and predicted to be in group j" (scikit-learn, confusion_matrix API reference, as of 26 November 2026; the page shows scikit-learn 1.9.1). The function returns an array "of shape (n_classes, n_classes)." In other words:

  • A classifier with 2 classes has a 2×2 matrix (4 cells).
  • A classifier with 3 classes has a 3×3 matrix (9 cells).
  • A classifier with n classes has an n×n matrix (n² cells), of which n are on the diagonal (correct) and n² − n are distinct error types.

That last count is the point. A three-class document sorter has six distinct ways to be wrong. A ten-class one has ninety. Accuracy collapses all of them into a single "wrong" bucket.

Documented behavior. The scikit-learn function also accepts a labels argument, a "List of labels to index the matrix," which "may be used to reorder or select a subset of labels"; if it is not given, the labels "that appear at least once in y_true or y_pred are used in sorted order" (scikit-learn API). That detail matters in practice. If a rare class happens not to appear in a particular test batch, and is never predicted, it silently drops out of the matrix unless you pass the full label list. A matrix that is missing a row is easy to misread as a smaller, cleaner problem.

The scikit-learn user guide gives a small worked case. With true labels [2, 0, 2, 2, 0, 1] and predictions [0, 0, 2, 2, 0, 2], the function returns:

[[2, 0, 0],
 [0, 0, 1],
 [1, 0, 2]]

Row 0 says both true class-0 items were predicted as class 0. Row 1 says the single true class-1 item was predicted as class 2. Row 2 says of three true class-2 items, one was predicted as class 0 and two as class 2 (scikit-learn, Metrics and scoring, §Confusion matrix). Accuracy for that example is 4/6. The matrix adds that class 1 was never recognized at all, a fact the 0.67 does not reveal.

2. The axis trap: always read the labels

There is no single universal layout. scikit-learn puts the true class on the rows and the predicted class on the columns, and says so explicitly: the function computes "the confusion matrix with each row corresponding to the true class (Wikipedia and other references may use different convention for axes)" (scikit-learn user guide). The API page repeats the warning in its references: "Wikipedia and other references may use a different convention for axes" (scikit-learn API).

The earlier version of this page presented the opposite layout (rows = predicted, columns = actual) as the layout. That layout exists and is used in some textbooks and tools, but it is not the default in the most widely used Python library, and presenting either one as universal leads directly to swapped precision and recall. If you read a scikit-learn matrix with the other convention in mind, every "recall" you compute is really a precision and vice versa.

Editorial suggestion. Treat every confusion matrix as unlabeled until you have found, in the figure or the code that produced it, which axis is true and which is predicted. When you publish one, label both axes in words ("true class", "predicted class"), not just with class names. This page uses scikit-learn's convention throughout: rows = true, columns = predicted.

3. The binary case: four cells with names

For two classes, the four cells have conventional names. With the negative class as 0 and the positive class as 1, scikit-learn states that "in binary classification, the count of true negatives is C(0,0), false negatives is C(1,0), true positives is C(1,1) and false positives is C(0,1)" (scikit-learn API). In its row-equals-true layout:

true \ predictedpredicted negative (0)predicted positive (1)
true negative (0)TN (true negative)FP (false positive)
true positive (1)FN (false negative)TP (true positive)

The user guide shows how to unpack them in code: tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel().tolist(), which for its example returns (2, 1, 2, 3) (scikit-learn user guide). The order (tn, fp, fn, tp) follows from reading the 2×2 array row by row. It is a frequent source of bugs when someone assumes the order is (tp, fp, fn, tn).

Two more points about the binary case:

  • "Positive" is a choice, not a fact. It means "the class we are trying to detect," not "the good outcome." In fraud detection the positive class is fraud; in document triage it is "urgent." The scikit-learn guide notes that in binary metrics the positive class "is labelled 1 (though this may be configurable through the pos_label parameter)" (scikit-learn user guide). Swap which class is positive and precision, recall and F1 all change.
  • Each binary metric uses only part of the table. Precision uses only the predicted-positive column. Recall uses only the true-positive row. F1 never looks at TN. That is why a single metric can look healthy while one cell of the table is a disaster (section 8).

4. What is calculated from the matrix

Every common classification metric is arithmetic on the cells. The definitions below come from the scikit-learn user guide and Google's Machine Learning Crash Course (scikit-learn user guide; Google for Developers, ML Crash Course, "Classification: Accuracy, recall, precision, and related metrics", page last updated 2026-01-12).

MetricFormula (binary)Plain-language questionCells used
Accuracy(TP + TN) / allOf all predictions, how many were right?all four
PrecisionTP / (TP + FP)Of the items flagged positive, how many really were?predicted-positive column
Recall (sensitivity, true positive rate)TP / (TP + FN)Of the real positives, how many were found?true-positive row
Specificity (true negative rate)TN / (TN + FP)Of the real negatives, how many were correctly left alone?true-negative row
False positive rateFP / (FP + TN)Of the real negatives, how many were wrongly flagged?true-negative row
F12TP / (2TP + FP + FN)Harmonic mean of precision and recallall but TN

In words, from the scikit-learn guide: "Intuitively, precision is the ability of the classifier not to label as positive a sample that is negative, and recall is the ability of the classifier to find all the positive samples" (scikit-learn user guide). Google's course gives recall a second name that is useful in triage settings, "probability of detection," and calls the false positive rate "the probability of false alarm" (Google ML Crash Course).

Correction to the earlier page. The previous version of this page listed "The proportion of correctly classified instances (precision and recall)." That phrase is the definition of accuracy. Precision and recall are not proportions of all instances; each is a proportion of one row or one column of the matrix, as the table shows. The earlier page's "Key facts" list gave the correct precision and recall formulas, so the page contradicted itself.

For more than two classes, each class gets its own precision and recall by treating it as "positive" and everything else as "negative." In the row-equals-true layout, class k's recall is the diagonal cell divided by row k's total, and class k's precision is the diagonal cell divided by column k's total. The guide puts it this way: "In a multiclass and multilabel classification task, the notions of precision, recall, and F-measures can be applied to each label independently" (scikit-learn user guide).

5. Same accuracy, different mistakes (hypothetical example)

Hypothetical example. A team tests two document classifiers, X and Y, on 300 documents: 100 invoices, 100 receipts and 100 contracts. The data are invented for illustration; the arithmetic was checked with a short script. Rows are the true class, columns the predicted class.

Classifier X

true \ predictedinvoicereceiptcontract
invoice90100
receipt10900
contract00100

Classifier Y

true \ predictedinvoicereceiptcontract
invoice10000
receipt01000
contract02080

Both have 280 correct predictions out of 300, so both have accuracy 0.933. Per class, they are very different:

ClassX precisionX recallY precisionY recall
invoice0.900.901.001.00
receipt0.900.900.8331.00
contract1.001.001.000.80

X mixes up invoices and receipts in both directions, ten each way, and never misses a contract. Y is perfect on invoices and receipts but files one in five contracts as a receipt. Y's receipt precision is 100/120 = 0.833, because 20 of the 120 documents it called "receipt" were contracts.

Here is the striking part. Common summary metrics do not separate them either. Macro-averaged recall (which scikit-learn's balanced_accuracy_score computes, see section 9) is 0.933 for both, because X's recalls (0.9, 0.9, 1.0) and Y's (1.0, 1.0, 0.8) average to the same value. Macro-averaged F1 is 0.933 for X and 0.933 for Y to three decimal places (0.9333 versus 0.9327). A dashboard showing accuracy, balanced accuracy and macro F1 would show two nearly identical classifiers. The matrix shows that one of them loses contracts.

If a contract filed as a receipt means a missed legal obligation (a renewal deadline nobody sees, a liability clause nobody reviews), Y is much worse for this job, and none of the single numbers can tell you.

6. Direction matters: "A called B" is not "B called A"

The matrix is not symmetric, and the asymmetry carries meaning. In classifier Y, contracts are called receipts, but receipts are never called contracts. That direction tells you something about what the model has learned: perhaps short contracts with a price table look like receipts to it, while nothing about a receipt looks contractual. It also tells you what the business consequence is. A receipt wrongly flagged as a contract costs a reviewer a minute. A contract wrongly filed as a receipt may cost far more.

Editorial suggestion. Weight the off-diagonal cells by consequence. One simple way is a cost table with the same shape as the matrix, where each off-diagonal cell holds the cost of that specific mistake.

Hypothetical example, continued. Suppose the team estimates that confusing an invoice with a receipt (either direction) costs 1 unit of rework, and filing a contract as a receipt costs 50 units (expected cost of a missed obligation). Multiply each error count by its cost and add:

  • X: 10 × 1 + 10 × 1 = 20 units
  • Y: 20 × 50 = 1,000 units

The costs here are invented, and real cost estimates are uncertain. The point is the mechanism: once you attach a consequence to each cell, two classifiers with the same accuracy can differ by a factor of fifty. Accuracy implicitly treats every off-diagonal cell as costing the same.

The scikit-learn documentation describes the same idea in its discussion of decision thresholds: classification is "best divided into two parts," a statistical problem of predicting probabilities and "the decision problem to take concrete action based on those probability predictions," and its tuned-threshold example optimizes "a utility metric defined by the business" (scikit-learn, "Tuning the decision threshold for class prediction"). A cost table is one way to write that utility down.

7. Normalization: turning counts into rates

Raw counts are hard to compare across classes of different sizes. scikit-learn's normalize argument "Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population" (scikit-learn API). The user guide spells out the options: "'pred', 'true', and 'all' which will divide the counts by the sum of each columns, rows, or the entire matrix, respectively" (scikit-learn user guide).

Each normalization answers a different question:

NormalizationDivides byDiagonal showsUse it to ask
'true' (rows)each row totaleach class's recall"When the document really is a contract, where does it end up?"
'pred' (columns)each column totaleach predicted label's precision"When the model says 'receipt', what is the document really?"
'all'grand totalshare of all items"What fraction of the whole workload is each mistake?"

Hypothetical example, continued. Classifier Y, normalized by true class (rows):

true \ predictedinvoicereceiptcontract
invoice1.000.000.00
receipt0.001.000.00
contract0.000.200.80

The bottom row reads: "a true contract has an 80% chance of being called a contract and a 20% chance of being called a receipt." Normalized by predicted class (columns), the receipt column becomes 0.00 / 0.833 / 0.167 from top to bottom: "when Y says 'receipt', about one time in six it is really a contract." Both views come from the same nine counts; they answer different questions, and both are worth looking at.

Two cautions. First, normalized matrices hide sample size. A row with 8 items and a row with 8,000 both show neat decimals. Always report the counts alongside, or at least the row totals. Second, say which normalization you used. A row-normalized and a column-normalized matrix of the same data look different and are easily confused if the caption does not say.

8. Imbalance: where one number misleads most

When one class is far more common than another, accuracy is dominated by the common class. Google's course gives the canonical illustration: "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 ML Crash Course). Its guidance table says of accuracy: "Avoid for imbalanced datasets."

The confusion matrix exposes this at a glance. The do-nothing model's matrix has an entire empty column: zero true positives and zero false positives. No single-number summary is as immediately damning as a column of zeros.

Imbalance can also fool metrics other than accuracy. Davide Chicco and Giuseppe Jurman, writing in BMC Genomics, constructed a set of synthetic use cases to show this (Chicco & Jurman 2020, BMC Genomics 21:6). In their "Use case A1," a dataset of 91 positives and 9 negatives produces the confusion matrix TP = 90, FN = 1, TN = 0, FP = 9. The classifier finds almost every positive but recognizes none of the negatives. Yet "accuracy = 0.90 and F1 score = 0.95, both close to the best possible value." The Matthews correlation coefficient (MCC), which uses all four cells, came out at −0.03, close to the value expected from coin-tossing. The authors' conclusion, an editorial position from primary researchers, is that MCC "produces a high score only if the prediction obtained good results in all of the four confusion matrix categories," and they recommend it over accuracy and F1 for binary tasks.

The paper also documents MCC's own limitation: it "is undefined when a whole row or column of M is zero, as it happens in the previously cited case of the trivial majority classifier" (Chicco & Jurman 2020). They propose conventions for filling in those cases, but the practical lesson is the same as for every summary metric: when a metric comes back undefined or strange, go back to the matrix.

What this does and does not show. The use cases are synthetic, chosen by the authors to illustrate where metrics disagree. They show that F1 and accuracy can mislead; they do not show how often that happens in any particular field. The matrix itself sidesteps the debate about which summary is best, because it shows the four (or n²) counts directly.

9. Multi-class summaries: macro, weighted, micro

When people do want a single number for a multi-class problem, the choice of averaging changes what the number means. scikit-learn's guide describes the main options (scikit-learn user guide):

  • Macro "simply calculates the mean of the binary metrics, giving equal weight to each class." The guide notes that "In problems where infrequent classes are nonetheless important, macro-averaging may be a means of highlighting their performance," but also that "the assumption that all classes are equally important is often untrue, such that macro-averaging will over-emphasize the typically low performance on an infrequent class."
  • Weighted "accounts for class imbalance by computing the average of binary metrics in which each class's score is weighted by its presence in the true data sample." This lets big classes dominate, much like accuracy.
  • Micro "gives each sample-class pair an equal contribution to the overall metric." For ordinary multi-class problems the guide warns: "If all labels are included, 'micro'-averaging in a multiclass setting will produce precision, recall and F that are all identical to accuracy."

That last point surprises people. A report that lists "micro-F1 = 0.93" for a single-label multi-class problem has reported accuracy under another name.

Balanced accuracy is closely related. scikit-learn's balanced_accuracy_score is "the macro-average of recall scores per class," and it "avoids inflated performance estimates on imbalanced datasets" (scikit-learn user guide, §Balanced accuracy score). The guide adds that if "the conventional accuracy is above chance only because the classifier takes advantage of an imbalanced test set, then the balanced accuracy, as appropriate, will drop to 1/n_classes." It also flags that there is "no certain consensus in the literature" on the multi-class definition, so a paper reporting "balanced accuracy" may mean something slightly different.

As section 5 showed, even balanced accuracy can be identical for classifiers with very different error patterns. It is a better single number than accuracy on imbalanced data, but it is still a single number.

10. Multi-label problems: one small matrix per label

Some tasks let an item carry several labels at once: a document can be both "contains personal data" and "needs signature." There is no single n×n matrix for that, because a prediction is not one class. scikit-learn's multilabel_confusion_matrix instead "computes class-wise (default) or sample-wise (samplewise=True) multilabel confusion matrix," producing one 2×2 table per label, where for label i "the count of true negatives for class i is C(i,0,0), false negatives is C(i,1,0), true positives is C(i,1,1) and false positives is C(i,0,1)" (scikit-learn user guide, §Multi-label confusion matrix).

The guide notes the same function "also treats multiclass data as if it were multilabel," which is a convenient way to get each class's one-versus-rest counts from an ordinary multi-class problem. What you lose in that view is the cross-class information: a one-versus-rest table for "contract" tells you 20 contracts were missed, but not that all 20 went to "receipt." For single-label problems, keep the full n×n matrix.

11. One matrix, one threshold

Most classifiers output a score or probability, and a threshold turns that score into a label. Change the threshold and every cell of the matrix moves. Google's course is explicit: "All of the metrics in this section are calculated at a single fixed threshold, and change when the threshold changes" (Google ML Crash Course).

scikit-learn documents that its binary classifiers use hard-coded cut-offs by default: "a positive class is predicted when the conditional probability P(y|X) is greater than 0.5 (obtained with predict_proba) or if the decision score is greater than 0 (obtained with decision_function)," and that "While these hard-coded rules might at first seem reasonable as default behavior, they are most certainly not ideal for most use cases" (scikit-learn, threshold tuning guide). The library includes confusion_matrix_at_thresholds, which returns the four counts at every distinct score threshold so you can see how the table shifts (scikit-learn user guide).

Practical consequences:

  • A confusion matrix is a snapshot of one operating point. Report the threshold with it.
  • Comparing two classifiers' matrices is only fair at comparable operating points, for example both tuned to the same recall on validation data.
  • Curves summarize many thresholds at once. For a binary problem, ROC curves plot recall against false positive rate across thresholds; precision-recall curves plot precision against recall. Saito and Rehmsmeier showed that on imbalanced data ROC plots "can be deceptive with respect to conclusions about the reliability of classification performance," whereas precision-recall plots "can provide the viewer with an accurate prediction of future classification performance due to the fact that they evaluate the fraction of true positives among positive predictions" (Saito & Rehmsmeier 2015, PLoS ONE 10(3): e0118432). Those curves are built from a sequence of confusion matrices, one per threshold.

12. Label errors show up as model confusions

A confusion matrix compares predictions with the test set's labels, and those labels are not always right. When a test item is mislabeled, a correct prediction is counted as an error, and it lands in an off-diagonal cell where it looks exactly like a model confusion.

How common is this? Curtis Northcutt, Anish Athalye and Jonas Mueller examined the test sets of ten widely used computer vision, natural language and audio benchmarks. Observed result: "we estimate an average of at least 3.3% errors across the 10 datasets, where for example label errors comprise at least 6% of the ImageNet validation set." Candidate errors were found algorithmically and then checked by crowd workers, and "51% of the algorithmically-flagged candidates are indeed erroneously labeled, on average across the datasets" (Northcutt, Athalye & Mueller 2021, NeurIPS Datasets and Benchmarks, arXiv:2103.14749). The paper also found that model rankings could change on corrected labels; for example, on ImageNet with corrected labels, "ResNet-18 outperforms ResNet-50 if the prevalence of originally mislabeled test examples increases by just 6%."

Those are large, carefully built public benchmarks. A small in-house test set labeled quickly by one person may be worse or better; the study does not say. The practical lesson is general: before concluding that the model confuses contracts with receipts, open the documents in that cell. Some will be genuine model errors, some will be genuinely ambiguous documents, and some will be test labels that are simply wrong. Each needs a different fix (model, label definitions, or the test set itself).

13. Small cells are noisy

A confusion matrix makes every count look equally solid. They are not. A class with 10 test items can swing from 90% recall to 70% with two errors, and the matrix does not show that uncertainty.

One standard way to express it is a confidence interval for a proportion. The NIST/SEMATECH e-Handbook of Statistical Methods describes the Wilson interval ("introduced by Wilson (1927), recommended by Brown, Cai and DasGupta (2001) and Agresti and Coull (1998)") and notes that "its worth does not strongly depend upon the value of n and/or p," and that, unlike the common normal-approximation formula, "the lower limit cannot be negative" (NIST/SEMATECH e-Handbook, §7.2.4.1 Confidence intervals).

Hypothetical example. Applying the Wilson formula from that page (95% level) to a class's recall, computed with a short script:

Correct / class sizeObserved recallApproximate 95% Wilson interval
9 / 100.900.60 to 0.98
45 / 500.900.79 to 0.96
180 / 2000.900.85 to 0.93
7 / 100.700.40 to 0.89

With ten items, a class scoring 0.90 and a class scoring 0.70 have heavily overlapping intervals. You cannot tell them apart. With two hundred, you can. This treats each test item as an independent draw, which real test sets only approximate, so read the intervals as a rough guide to how much a cell could move, not as exact bounds.

Editorial suggestion. Put the row total next to each row of a published matrix, and do not draw conclusions from cells built on a handful of items.

14. How to read a confusion matrix: a checklist

Editorial suggestion. A sequence that works for most matrices:

  1. Find the axes. Which side is true, which is predicted? Is it raw counts or normalized, and if normalized, by rows, columns or the total?
  2. Check the class list. Are all expected classes present? A missing row (section 1) or an empty column (section 8) is the first thing to notice.
  3. Read the row totals. These are the class sizes in the test set. Note which classes are small (section 13) and how imbalanced the set is.
  4. Read the diagonal, row by row. Divide each diagonal cell by its row total for per-class recall. Which class is weakest?
  5. Read the columns. Divide each diagonal cell by its column total for per-class precision. Is any predicted label a "sink" that absorbs many other classes?
  6. Find the largest off-diagonal cells. These are the main confusions. Note their direction.
  7. Attach consequences. Which confusions are expensive? A cost table (section 6) makes this explicit.
  8. Open the examples. Pull real items from the biggest and most costly cells. Sort them into model error, ambiguous item and label error (section 12).
  9. Note the threshold and the test set. The matrix belongs to one operating point on one sample of data (section 11).
  10. Only then look at summary numbers, and choose ones that match the costs: per-class recall for the class you must not miss, precision for the label whose false alarms are expensive.

15. How to report one

Editorial suggestion. A reader should be able to reconstruct the important facts without the raw data. A good report includes:

ItemWhy
The full matrix in counts, with both axes labeled in wordsCounts preserve sample size; labels prevent the axis trap
Row totals (class sizes)Shows imbalance and which cells are noisy
A row-normalized version (per-class recall) and, if useful, a column-normalized oneMakes per-class rates comparable
The threshold or decision rule usedThe matrix changes with it
How the test set was drawn and labeled, and by whomLabel quality and representativeness limit what the matrix means
Per-class precision and recallThe numbers most decisions actually need
Any summary metric, with its averaging stated"Micro-F1" in a single-label multi-class task is accuracy (section 9)
A short note on the largest confusions, with examplesTurns the table into an action list

For problems with many classes (dozens or hundreds), the full table becomes unreadable. A reasonable approach is to publish the full matrix as a downloadable file, and in the text show the top confusions (the largest off-diagonal cells) plus per-class precision and recall sorted from worst to best.

16. What this page used to say, and what changed

This page replaces an earlier, unsourced version. Three corrections, as flagged in the Grok Bot draft that this longread expands:

  1. Precision and recall are not "the proportion of correctly classified instances." That is accuracy. Precision is TP / (TP + FP) and recall is TP / (TP + FN) (section 4).
  2. There is no single axis convention. The earlier page presented rows = predicted as the layout. scikit-learn uses rows = true and warns that other references differ (section 2). Readers must check the labels.
  3. Confusion matrices are n×n, not only 2×2. The multi-class case is where they are most informative, because the number of distinct error types grows as n² − n (sections 1 and 5).

The earlier page also suggested uses in "pollinator species identification" and "bee monitoring systems." Those are plausible applications of any classifier, but the page cited no system that does them, and this longread makes no claim about any bee-related classifier.

17. What the evidence does and does not show

  • Documented: the definitions, the axis convention in scikit-learn, normalization options, averaging behavior and threshold defaults are documented by the library itself, as of 26 November 2026. Library defaults can change between versions; check the version you are using.
  • Observed result: Northcutt and colleagues measured label error rates in ten specific public test sets. The rates do not transfer automatically to other datasets.
  • Illustration, not frequency: Chicco and Jurman's use cases show that accuracy and F1 can mislead on imbalanced data; they are constructed examples, not a survey of how often that happens.
  • Not shown here: which classifier is best for any real document workflow. All the invoice, receipt and contract numbers on this page are hypothetical. Their purpose is to show what a matrix can reveal, not to report results from a real system.
  • Limits of the matrix itself: it reflects one test set, one threshold and one labeling. It counts errors but does not explain them; finding out why a cell is large still means looking at the items in it.

Related reading on Apiary

  • precision-vs-recall-in-document-triage
  • how-imbalanced-test-sets-hide-weak-classifiers

Sources

Last checked: 2026-11-26.

  1. scikit-learn developers. "sklearn.metrics.confusion_matrix" API reference (scikit-learn 1.9.1 documentation). https://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html - definition C(i, j), binary cell positions, labels and normalize parameters, axis-convention warning.
  2. scikit-learn developers. "Metrics and scoring: quantifying the quality of predictions" user guide (§Confusion matrix; §Precision, recall and F-measures; §Balanced accuracy score; §Multi-label confusion matrix; averaging). https://scikit-learn.org/stable/modules/model_evaluation.html - row = true convention, worked 3×3 example, tn/fp/fn/tp unpacking, normalization options, precision/recall wording, macro/weighted/micro, micro equals accuracy, balanced accuracy, confusion_matrix_at_thresholds, multilabel matrices.
  3. scikit-learn developers. "Tuning the decision threshold for class prediction" user guide. https://scikit-learn.org/stable/modules/classification_threshold.html - default 0.5 / 0 cut-offs, statistical versus decision problem, business utility metric.
  4. Google for Developers. "Classification: Accuracy, recall, precision, and related metrics." Machine Learning Crash Course, last updated 2026-01-12. https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall - metric definitions, 1% / 99% accuracy example, single-threshold caveat, probability of detection / false alarm, guidance table.
  5. Chicco, D., Jurman, G. "The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation." BMC Genomics 21, 6 (2020). https://doi.org/10.1186/s12864-019-6413-7 - Use case A1 counts and scores, MCC rationale, MCC undefined when a row or column is zero (full text read at link.springer.com).
  6. Northcutt, C. G., Athalye, A., Mueller, J. "Pervasive Label Errors in Test Sets Destabilize Machine Learning Benchmarks." NeurIPS 2021 Datasets and Benchmarks Track; arXiv:2103.14749. https://arxiv.org/abs/2103.14749 - 3.3% average and 6% ImageNet test-label errors, 51% validation rate, ranking changes (PDF read).
  7. Saito, T., Rehmsmeier, M. "The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets." PLoS ONE 10(3): e0118432 (2015). https://doi.org/10.1371/journal.pone.0118432 - ROC can be deceptive on imbalanced data; PR plots evaluate fraction of true positives among positive predictions (full text read via Europe PMC, PMC4349800).
  8. NIST/SEMATECH. "e-Handbook of Statistical Methods," §7.2.4.1 Confidence intervals. https://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm - Wilson interval for a proportion, recommendation history, non-negative lower limit.

This page was researched and drafted by an AI assistant (Claude, Anthropic) for Apiary, expanding an earlier Grok Bot draft. Sources were opened and read on 26 November 2026. It has not been reviewed by a human expert and is not founder-verified. Status: candidate.

Frequently asked
What is Confusion Matrix: Seeing Which Mistakes a Classifier Makes, Not Just How Many about?
A confusion matrix is a table that counts every combination of true class and predicted class in a test set. If a document classifier sorts files into…
What should you know about 1. What a confusion matrix is?
The scikit-learn documentation gives the standard definition: "By definition a confusion matrix C is such that C(i, j) is equal to the number of observations known to be in group i and predicted to be in group j" ( scikit-learn, confusion_matrix API reference , as of 26 November 2026; the page shows scikit-learn…
What should you know about 2. The axis trap: always read the labels?
There is no single universal layout. scikit-learn puts the true class on the rows and the predicted class on the columns , and says so explicitly: the function computes "the confusion matrix with each row corresponding to the true class (Wikipedia and other references may use different convention for axes)" (…
What should you know about 3. The binary case: four cells with names?
For two classes, the four cells have conventional names. With the negative class as 0 and the positive class as 1, scikit-learn states that "in binary classification, the count of true negatives is C(0,0), false negatives is C(1,0), true positives is C(1,1) and false positives is C(0,1)" ( scikit-learn API ). In its…
What should you know about 4. What is calculated from the matrix?
Every common classification metric is arithmetic on the cells. The definitions below come from the scikit-learn user guide and Google's Machine Learning Crash Course ( scikit-learn user guide ; Google for Developers, ML Crash Course, "Classification: Accuracy, recall, precision, and related metrics" , page last…
References & sources
  1. Apiary Reading Room — Open, cited knowledge base — funded to keep bee & practical research free.
From the Apiary Reading Room. Opinion & editorial — not financial advice. We don't overclaim.
More from the Reading Room