Classification Evaluation (Confusion Matrix and Metrics)

Context: FIT1043_MOC, FIT2086_MOC · how good is a classifier? · counts outcomes in a confusion matrix · the right metric depends on the cost of each error · scores the output of Logistic Regression · sweep the threshold instead of fixing it ➔ ROC and AUC · score the probabilities instead of the labels ➔ Logarithmic Loss

Quick Revision

  • 🎯 Objective: score a classifier ➔ build a confusion matrix (TP/FP/FN/TN), then compute the metric that matches the task.
  • 📦 Core Components: accuracy | sensitivity/recall | specificity | precision | false-positive rate.
  • ⚡ Key Constraint: accuracy alone misleads — choose the metric by which error is worse (a missed fraud vs a blocked good email), and check it against the class frequencies, not against .

📝 How It Works

1. The Confusion Matrix

Predicted PositivePredicted Negative
Actual PositiveTP (true positive)FN (false negative)
Actual NegativeFP (false positive)TN (true negative)

2. The Five Metrics

  • Accuracy ➔ overall correct: .
  • Sensitivity / Recall ➔ of actual positives, how many caught: .
  • Specificity ➔ of actual negatives, how many correct: .
  • False Positive Rate ➔ of actual negatives, how many wrongly flagged: .
  • Precision ➔ of predicted positives, how many correct: .

3. Which Metric When (it depends)

  • Spam filter ➔ optimise precision / specificity — a FN (spam in inbox) is tolerable; a FP (good mail blocked) is costly.
  • Fraud detector ➔ optimise sensitivity/recall — a FP (normal flagged) is tolerable; a FN (missed fraud) is costly.
  • Covid test ➔ balance sensitivity (catch the sick) vs specificity (don’t alarm the healthy).

4. The FIT2086 Layer — Notation, Decision Rule and Baseline

  • Where the labels come from ➔ a probabilistic model gives ; the predicted class is ➔ equivalently a threshold of (ROC and AUC).
  • Classification accuracy as an indicator sum ➔ over new test individuals:

where is when the condition holds and otherwise ⟹ the proportion of correct guesses on data the model was not fitted to.

  • Names used in FIT2086 ➔ sensitivity is the true positive rate ; specificity is the true negative rate — same quantities as above, exam-facing names.
  • Range ➔ : perfectly incorrect, perfectly correct.
  • The baseline is not always ➔ for balanced binary classes, is the accuracy of random guessing; for imbalanced classes a trivial majority-class classifier already scores above ⟹ the relevant baseline is set by the class frequencies.
  • Orientation warning ➔ the lecture draws the matrix both ways (predicted as rows on one slide, actual as rows on the next) ⟹ read the axis labels, never the cell positions.

⚖️ Core Decision Matrix

MetricQuestion it answersFormula
Accuracyoverall how often correct?
Recall (sensitivity, TPR)of actual +, how many found?
Specificity (TNR)of actual −, how many correct?
Precisionof predicted +, how many right?

When It Flips: recall and precision pull apart — flagging everything positive gives perfect recall but poor precision; flagging only sure cases gives high precision but poor recall. The task's error costs pick which to favour.

📊 Exam Execution Trace

Applied Exercise 1

Problem: , , , . Compute accuracy, recall, precision. Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: 70% accurate; catches 80% of positives (recall) but only 67% of its positive calls are right (precision).

Applied Exercise 2 — a decent accuracy hiding a broken classifier

Problem: test individuals give , , , . Report CA, sensitivity and specificity, and judge the classifier.

Final Extracted Output: accurate looks respectable, but it catches only of the positives while getting of the negatives right ⟹ the accuracy is carried almost entirely by the majority negative class. With negatives, predicting “always ” would already score — this model beats that baseline by less than one point.

🧠 Active Recall