A confusion matrix compares the outcomes a method produced with independently established reference answers. In a two-class task, each counted decision is a correct positive, a correct negative, a false positive, or a false negative. The matrix lets a reader see which errors made up an overall rate and calculate rates with the right denominators.
Start with the task, the unit being counted, and the row and column labels. A table can be transposed without changing any measurements. Misreading its orientation can swap the two error types or lead to dividing by the wrong total. Read the labels before drawing a conclusion about performance.
Key terms
- Confusion matrix
- A table cross-tabulating observed or predicted decisions against independently established reference labels.
- Specificity
- The proportion of known negative trials correctly classified as negative under a specified rule.
- False-positive rate
- The proportion of known negative trials that the method classifies as positive under a specified rule.
- False-negative rate
- The proportion of known positive trials that the method classifies as negative under a specified rule.
Learning Objectives
- Identify reference answers, predictions, and the four cells of a binary confusion matrix.
- Reconstruct row and column totals and calculate rates for a defined question.
- Explain how changing decision rules and excluded cases affects the matrix.
- Report a matrix with its unit, labels, denominator, and test conditions.
Establish What “Positive” Means
The positive class is the outcome of interest defined by the examination. In a document quality test, a positive might be a record missing a required unit. In a different procedure, a positive might be a record suitable for publication. Describe the class in ordinary language. Changing the target can change which category a particular disagreement belongs to.
Identify the reference used to decide which outcomes were right. An independently checked spreadsheet can supply reference values for a data extraction test. A provisional software output may need its own validation before it can play that role. The reference data lesson describes how to document both the labels and the basis for them.
Identify the sampling unit. A test might include one decision per file, per form field, or per comparison between two images. If several choices appear for one case, determine whether the result represents each choice or the full case's disposition. Counting all the pieces as independent can obscure repeat observations and change what the rate measures.
Keep the comparison rule visible. A scored response may be assigned to the positive class above a cutoff, or the method may classify directly. Document what happens at the cutoff, which score version was used, and whether humans reviewed proposals before the predicted labels were counted. The matrix describes that particular combination of measurement and decision.
Name the test population and period. A matrix based on a set chosen to contain equal counts describes that set. Its overall accuracy or fraction of correct positive calls can change with a real case mix. See class imbalance for how counts influence aggregate results and review volume.
Check that the reported labels refer to the intended truth claim. A benchmark can label a document positive because its owner confirmed a missing attachment, while the model tries to detect only whether a placeholder appears. Those labels describe related but different properties. Correct any mismatch between the comparison rule and the reference definition before interpreting the cell counts.
Read Four Cells and Rebuild the Totals
Use both dimensions to identify each cell. A true positive is a known positive labeled positive, while a false negative is a known positive labeled negative. A false positive is a known negative labeled positive, while a true negative is a known negative labeled negative. When axes are transposed, the meanings remain tied to the reference and prediction labels.
Try a simple example with archive records. Assume 40 records truly have the target issue and 60 truly lack it. The detector flags 30 of the 40 and also flags 12 of the 60. That yields 30 true positives, 10 false negatives, 12 false positives, and 48 true negatives. Every classified record enters exactly one cell.
Rebuild both marginal totals. There are 42 predicted positives, because the detector flagged 30 correctly and 12 incorrectly. There are 58 predicted negatives, because it missed 10 and correctly left 48 unflagged. The two prediction totals give 100. The reference totals of 40 and 60 also give 100, which provides a quick internal check.
Some reports publish counts arranged in a row for each trial condition instead of showing a square matrix. The columns can appear in any order. Reconstruct the square using the labels, then check whether totals and published rates agree within rounding. Keep the underlying counts if they are available. If totals remain inconsistent, record which interpretation needs clarification.
Look for a possible mixture of counts and percentages. A row-normalized matrix can show percentages of known classes when reference labels are rows. In a matrix with predicted labels as rows, the same row operation gives a different interpretation. A percentage describing the whole table has yet another denominator. Inspect the scale, axis labels, and marginal counts before comparing cells.
Work From the Question to the Denominator
To ask what fraction of real issues were found, divide true positives by all known positives. The archive exercise gives 30 of 40, or 75 percent recall. To ask what fraction of flags were actually relevant, divide true positives by all predicted positives. That yields 30 of 42, or about 71.4 percent precision for this set.
To ask how often ordinary records were flagged, divide false positives by all known negatives. The exercise gives 12 of 60, or 20 percent. Specificity uses the same known-negative denominator with the correct negatives in the numerator, which gives 48 of 60, or 80 percent. The two percentages sum to 100 when every known negative receives a binary decision.
The false-negative rate uses known positives as its denominator. In the example it is 10 of 40, or 25 percent. Overall accuracy is the fraction of all decisions in the two correct cells, which is 78 of 100. A report can give these totals alongside class-specific rates so a reader can compare the two error types.
When comparing matrices, check whether both describe the same threshold and case population. A higher specificity may follow from accepting fewer positive calls and can come with lower recall. The threshold lesson explains how to assess that tradeoff. If the input cases differ, differences in the cells may reflect the mix as well as the rule.
A zero cell can be meaningful even with substantial uncertainty. Zero false positives on six known negatives leaves less information about the underlying error rate than zero on 600 independently sourced negatives. Keep the denominator and sampling relationship visible. The small samples lesson gives examples of uncertainty for observed rates.
Account for Decisions Outside the Four Cells
A two-by-two matrix requires binary reference labels and binary predictions for the included records. Cases with missing reference answers, failed processing, or inconclusive responses cannot simply be placed in a correct or incorrect cell. Define how the workflow handles each status and identify the total eligible count before presenting any subset.
If the method can abstain, add a column for no decision or report a separate set of counts by reference class. This allows a reader to see whether the missing decisions were concentrated among positives or negatives. A binary matrix on the decided cases can still be useful, provided the report identifies the remaining cases and avoids implying that they were classified.
Compare two systems at the same workflow stage. An early model might flag 50 inputs, while subsequent review removes errors and adds missed cases. A matrix for the final reviewed result describes the combined procedure. A matrix for the model describes the first stage. Using one for each system confounds the comparison unless the different stages are the stated question.
Avoid pooling related cases without examining where errors cluster. Several files derived from one specimen may share a failure. A matrix built by pooling those files describes the observed files, while further inference can require an analysis of distinct sources. Report the counts of contributing cases and whether particular conditions account for a concentration of errors.
Track the eligible population through all stages. For example, an evaluation might receive 110 documents, identify 100 with reliable labels, and obtain model decisions for 98 of those. The matrix total is then 98. Give separate counts for the 10 records without suitable labels and the two labeled records without model decisions. This accounting shows which data are absent from the summary.
Read the Matrix as a Diagnostic Record
Inspect the errors before changing the decision rule. A common false positive can come from a repeated heading that resembles the target field. False negatives can cluster on low-quality scans. Reviewing independently labeled examples from each cell can show whether the same broad type of measurement failure accounts for the errors. Record which cases were reviewed and under what instructions.
A confusion matrix supports diagnosis at an aggregate level. It can identify whether one type of error dominates but may leave the cause unresolved. Trace representative errors back to source material and intermediate results. One large false-negative total can include several unrelated causes, such as missed regions, ambiguous labels, or threshold decisions after successful measurement.
Report a short account with counts and context. For example, “On 100 independently labeled archive records, the specified rule found 30 of the 40 records with the target issue and flagged 12 of the 60 records without it.” This tells readers which output they can interpret, how many errors occurred, and which denominators support that interpretation.
When the matrix will be used to compare releases, preserve the input list and labels along with the output. A result can maintain the same counts even if different cases are misclassified. Trace that change to the affected cases and support the intended use. The regression testing lesson explains why matching aggregate totals can conceal substitutions.
Before pooling across groups, decide what the combined matrix should represent. Adding every cell across sites weights the result by the number of decisions made at each site. Averaging site-specific percentages weights sites differently. Both summaries can be useful for stated questions. Retain site counts so a reviewer can see whether one high-volume source drove the overall result.
Does the reference class always occupy the rows?
What makes a false-positive rate different from the fraction of flags that are wrong?
What should happen to unresolved inputs in a matrix?
Why keep counts when reporting percentages?
Check Your Understanding
Sources
- 1.Yiliguoqi et al., Research on the Evaluation and Analysis of Road Surface Roughness Based on Smartphone Sensors and SVMTables 12 and 13 report the test counts, named classes, and performance measures for vehicle D.
- 2.Saito and Rehmsmeier, Evaluating Binary Classifiers on Imbalanced DatasetsDefines the four outcomes and commonly used measures calculated from a binary confusion matrix.