Model Evaluation: lesson 3 of 7

Model Evaluation

PATH 02MODULE 04LESSON 03 OF 07Next: Why Accuracy Is Not Enough

Reading a Confusion Matrix

Interpret true and false class outcomes before relying on summary metrics.

Beginner15 min readclassificationconfusion-matrixevaluation

Concept

A confusion matrix organizes binary predictions by actual and predicted class. With fraud as positive, a true positive is detected fraud; a false negative is missed fraud; a false positive is a legitimate transaction flagged as fraud; and a true negative is correctly cleared.

Actual / PredictedPositiveNegative
PositiveTrue positiveFalse negative
NegativeFalse positiveTrue negative

Always label orientation. In scikit-learn, confusion_matrix(y_true, y_pred) returns rows for actual classes and columns for predicted classes.

from sklearn.metrics import confusion_matrix
matrix = confusion_matrix(y_test, y_pred)

Why It Matters

The matrix reveals error types hidden by one score. Missing fraud and blocking legitimate payments have different costs. In medical screening, a false negative can miss disease; in spam filtering, a false positive can hide a legitimate email. The positive class means the class of interest, not a good outcome.

Read a Concrete Matrix

Suppose fraud is positive and rows are actual classes:

Actual / PredictedFraudLegitimate
Fraud82
Legitimate12978

The model detected eight fraud cases (true positives), missed two (false negatives), incorrectly flagged twelve legitimate transactions (false positives), and cleared 978 correctly (true negatives). The table makes the trade-off visible without yet choosing a summary metric. Moving the threshold can change all four counts.

Translate Each Cell Into a Decision

With fraud as the positive class, true positives are fraud transactions correctly blocked. False positives are legitimate transactions flagged for review, which can create customer friction. True negatives are legitimate transactions allowed normally. False negatives are fraud transactions missed by the system. Rows are actual outcomes; columns are predicted outcomes. Say that orientation aloud before interpreting any matrix, because reversing it changes the meaning of every cell.

Error costs depend on the domain. A fraud team may accept more false positives to reduce missed fraud. A spam filter may care strongly about false positives because hiding a legitimate message is disruptive. A medical screen may treat a missed disease case as especially serious. The matrix does not choose the policy; it makes the consequences visible.

From Matrix to Evaluation

confusion_matrix(y_test, y_pred) returns the counts for a chosen set of labels. Check the label order and state the positive class before presenting it. Now that we can see the kinds of mistakes a classifier makes, the next question is why accuracy alone can hide them.

Best Practices

Define the positive class, label axes, and discuss errors with the decision owner. Threshold changes alter these counts. The next lesson uses this vocabulary to explain why accuracy can fail; it introduces precision, recall, and F1 in depth.

Practice Questions

  1. Identify the false negative for fraud detection.
  2. Which error harms a spam filter's legitimate email user?
  3. Why must matrix orientation be stated?
  4. How can a threshold change matrix counts?
  5. In the example, how many fraud cases were missed?

Quick Quiz

  1. Are rows actual or predicted in scikit-learn? Answer: actual.
  2. What is a false positive? Answer: predicted positive when actual negative.
  3. Does positive mean good? Answer: no.

Key Takeaway

Key Takeaways

Confusion matrices make classification mistakes concrete before summary metrics hide their types.

Next Lesson

Next, learn why accuracy can conceal important matrix behavior.

Finish this lesson on your terms

Mark it complete when you have worked through the material and are ready to move on.