Tutorials › Exam PA - Predictive Analytics › Constructing and Orienting a Confusion Matrix

Exam PA · Classification Metrics and Thresholds · Tutorial 708 of 966

Constructing and Orienting a Confusion Matrix

Build and audit a confusion matrix by separating actual outcomes from model decisions and checking each count against the relevant totals.

Intermediate 10 min read

What You'll Learn

  • State which outcome is designated positive before organizing counts.
  • Distinguish actual outcomes from predicted decisions.
  • Calculate true positives, false negatives, false positives, and true negatives from overlapping totals.
  • Read matrices with actual outcomes on rows or columns.
  • Check cell counts against row totals, column totals, and the overall sample size.
  • Identify common errors caused by reversing axes or confusing a margin with a cell.

Why Matrix Orientation Matters

A classification model turns a score into a predicted category. To compare that decision with what actually happened, the observations must be organized by two separate facts: the actual outcome and the model's predicted outcome. A confusion matrix displays their combinations. It is simple to construct, but only if the positive class and the row and column meanings are stated clearly.

A matrix with the right four numbers in the wrong cells tells a different story from the correct matrix. For example, the number of cases predicted positive is not necessarily the number that actually is positive. The overlap between those groups is only one cell. This tutorial develops a reliable method for identifying that overlap and filling the remaining cells.

Definition: A confusion matrix is a table that cross-classifies evaluated cases by their actual class and their predicted class. For a binary outcome, first designate one class as positive and the other as negative. With actual classes in rows and predicted classes in columns:
  • True positive (TP): actually positive and predicted positive.
  • False negative (FN): actually positive and predicted negative.
  • False positive (FP): actually negative and predicted positive.
  • True negative (TN): actually negative and predicted negative.

“Positive” is a label for the outcome of interest, not a claim that the outcome is beneficial. In a hypothetical insurance review process, for instance, “requires additional review” could be designated positive even if the review itself is an administrative burden. State the definition in words before counting. Also state whether rows or columns represent actual outcomes; there is no universal layout that should be assumed without checking.

The counts should refer to the same set of evaluated cases: each case has one actual class and one predicted class. In an unweighted count matrix, every case contributes to exactly one of the four cells. Scores and thresholds determine predicted labels; once those labels are given, the matrix is a comparison of labels, not a table of scores.

A Reliable Construction Method

Think of the actual-positive cases as one group and the predicted-positive cases as another. Their intersection is TP. The actual-positive cases outside that intersection are FN. The predicted-positive cases outside it are FP. Cases belonging to neither positive group are TN. This set-based interpretation prevents a margin total from being mistaken for a cell.

$$ \begin{aligned} \text{Actual positive total} &= TP+FN,\\ \text{Actual negative total} &= FP+TN,\\ \text{Predicted positive total} &= TP+FP,\\ \text{Predicted negative total} &= FN+TN,\\ N &= TP+FN+FP+TN. \end{aligned} $$

These identities are also a practical audit. The two actual-class totals add to the same overall count as the two predicted-class totals. If they do not, at least one count, label, or transcription is wrong.

1
Name the positive class.
Write the outcome counted as positive in the specific problem context.
2
Read the axis labels.
Confirm which dimension is actual and which is predicted. Do not infer this only from where a matrix appears.
3
Place the overlap first.
The cases that are both actually positive and predicted positive are TP.
4
Fill in the remaining cells.
Subtract TP from the actual-positive total to get FN, and from the predicted-positive total to get FP. Use the overall or negative-class total to obtain TN.
5
Audit all margins.
Verify both actual totals, both predicted totals, and the grand total.

Worked Construction and Checks

Worked Example: Reconstructing a Review-Flag Matrix

A hypothetical insurer evaluates 240 claims. A claim is designated actually positive if it truly requires additional review. The model flags 50 claims for review, and 27 of those flagged claims truly require review. Construct the confusion matrix with actual outcomes in rows and predicted outcomes in columns.

Method. Treat the 27 claims that are both truly review-worthy and flagged as the overlap. That count is TP. The actual-positive total is 36? No such total is supplied directly, so it must not be assumed. The question gives only the predicted-positive total and the overlap; therefore, the actual-positive total and the complete matrix cannot be uniquely determined from the stated information.

To make the information sufficient, suppose the adjudication also establishes that 36 claims actually require review. Now the quantities can be calculated.

Step 1: TP. The 27 flagged claims that truly require review are both actually positive and predicted positive, so \(TP=27\).

Step 2: FN. Of the 36 actual-positive claims, 27 were flagged. The remainder were not flagged: \(FN=36-27=9\).

Step 3: FP. Of the 50 flagged claims, 27 were actual positives. The remaining flagged claims were actual negatives: \(FP=50-27=23\).

Step 4: TN. There are \(240-36=204\) actual negatives. Of these, 23 were flagged, leaving \(TN=204-23=181\).

Actual outcomePredicted positivePredicted negativeActual total
Positive: requires reviewTP = 27FN = 936
Negative: does not require reviewFP = 23TN = 181204
Predicted total50190240

Check. The actual-positive row totals \(27+9=36\); the actual-negative row totals \(23+181=204\); and \(36+204=240\). The predicted-positive column totals \(27+23=50\), and the predicted-negative column totals \(9+181=190\). Finally, \(27+9+23+181=240\).

Common mistake avoided. The 23 claims not truly requiring review are not the actual-negative total. There are 204 claims not truly requiring review; this is the total number of actual negatives. The false-positive count is the 23 flagged cases among those actual negatives. These counts are equal only if every actual negative is flagged.

Worked Example: Building the Matrix From Margins

A hypothetical screening program evaluates 500 accounts. A separate audit finds that 80 accounts are actually positive under the program's stated definition. The model predicts 110 accounts positive, and 62 accounts are both actually and predicted positive. Construct the matrix with actual classes in rows.

Method. Use the shared actual-positive and predicted-positive group to identify TP, then subtract it from each relevant margin.

Step 1: TP. The overlap is given directly, so \(TP=62\).

Step 2: FN. There are 80 actual positives in total. Thus \(FN=80-62=18\).

Step 3: FP. There are 110 predicted positives in total. Thus \(FP=110-62=48\).

Step 4: TN. The number of actual negatives is \(500-80=420\), so \(TN=420-48=372\).

Actual outcomePredicted positivePredicted negativeActual total
Positive621880
Negative48372420
Predicted total110390500

Check. The predicted-negative total is \(18+372=390\), which also equals \(500-110=390\). All four cells sum to \(62+18+48+372=500\).

Common mistake avoided. The 110 predicted positives are not TP. They include all 62 true positives and the 48 false positives. Similarly, the 80 actual positives include both TP and FN.

Reading a Matrix With Reversed Axes

A matrix may instead place predicted outcomes in rows and actual outcomes in columns. This is not incorrect, but the cell locations change. The names TP, FN, FP, and TN are determined by the two conditions in each cell, not by whether the cell is visually above or below the diagonal.

A short justification shows why the subtraction method works. Let \(A\) be the set of actually positive cases and \(P\) the set of predicted-positive cases. Their intersection \(A\cap P\) is TP. The actual-positive cases are partitioned into those in \(P\) and those not in \(P\), so \(A=(A\cap P)\cup(A\setminus P)\), with disjoint parts. Therefore \(|A|=TP+FN\). Likewise, \(P\) is partitioned into the true positives and predicted positives outside \(A\), giving \(|P|=TP+FP\). The remaining cases are outside both sets, which are the true negatives. These partitions establish the row, column, and grand-total identities.

Worked Example: Reorienting a Reported Table

A hypothetical equipment-monitoring report has 150 evaluated events. Its export labels rows as predicted outcome and columns as actual outcome. The report gives:

Predicted outcomeActual positiveActual negativePredicted total
Positive162945
Negative798105
Actual total23127150

Construct the same information using actual outcomes in rows and predicted outcomes in columns.

Method. Read each cell by its two labels before moving it. Predicted positive and actual positive is TP, so \(TP=16\). Predicted negative and actual positive is FN, so \(FN=7\). Predicted positive and actual negative is FP, so \(FP=29\). Predicted negative and actual negative is TN, so \(TN=98\).

Actual outcomePredicted positivePredicted negativeActual total
PositiveTP = 16FN = 723
NegativeFP = 29TN = 98127
Predicted total45105150

Check. Actual positives total \(16+7=23\); actual negatives total \(29+98=127\). Predicted positives total \(16+29=45\); predicted negatives total \(7+98=105\). The grand total is \(23+127=150\).

Common mistake avoided. When changing orientation, do not retain a cell's location while changing its row and column meanings. Here the value 29 remains FP because it is predicted positive and actually negative; it does not become FN merely because it moves to a different row in the reoriented table.

Common Exam Traps and a Final Audit

The most reliable habit is to annotate the table before inserting numbers: write “actual” and “predicted,” then label each class positive or negative. After the cells are filled, audit the margins rather than relying on visual intuition. A matrix can look plausible while assigning a margin total to a cell.

  • Confusing a total with a cell. “Actual negatives” is \(FP+TN\), whereas FP is only the actual-negative subset predicted positive.
  • Calling every predicted positive a TP. Predicted positives divide into TP and FP.
  • Reversing the axes. A cell's label follows its actual and predicted conditions, not its position in a particular display.
  • Leaving the positive class implicit. In a problem with several possible interpretations, define which outcome is positive before building the table.
  • Skipping totals. Check that the cells sum to the number of evaluated cases and reproduce every supplied margin.

A confusion matrix is the count-level foundation for later classification summaries. The matrix itself answers a concrete bookkeeping question: how many evaluated cases fall into each actual-predicted combination? Rates or scores derived from these counts should be considered only after the cells and their orientation have been verified.

Key takeaway: Define the positive class, label the actual and predicted dimensions, identify the TP overlap, and use subtraction to complete the other cells. Confirm every row total, column total, and the grand total before interpreting the matrix.

Check Your Understanding

For each problem, state the four cell counts using actual outcomes in rows and predicted outcomes in columns, unless the question specifies otherwise.

  1. A hypothetical review team evaluates 120 files. Twenty-four are actually positive, 35 are predicted positive, and 18 are both. Find TP, FN, FP, and TN. (Answer: TP = 18, FN = 6, FP = 17, TN = 79.)
  2. Among 180 evaluated records, 40 are actually positive and 140 actually negative. The predicted-negative total is 125, and TP is 31. Find all four cells and check the total. (Answer: TP = 31, FN = 9, FP = 24, TN = 116; total = 180.)
  3. A report uses predicted outcomes in rows and actual outcomes in columns. The predicted-positive row contains 16 actual positives and 29 actual negatives; the predicted-negative row contains 7 actual positives and 98 actual negatives. Identify the four cell counts by name. (Answer: TP = 16, FN = 7, FP = 29, TN = 98.)
  4. In a hypothetical maintenance study of 1,000 events, 120 events are actually positive, 200 are predicted positive, and 90 are true positives. Find the full matrix and verify both predicted totals. (Answer: TP = 90, FN = 30, FP = 110, TN = 770; predicted positive = 200 and predicted negative = 800.)
  5. A data set has 300 cases: 55 are actually positive, 245 are actually negative, 80 are predicted positive, and 42 are both actually and predicted positive. Find the remaining cells and show that the actual and predicted margins agree. (Answer: TP = 42, FN = 13, FP = 38, TN = 207; actual totals = 55 and 245, predicted totals = 80 and 220.)
Clinical Biostats