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 Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP (true positive) | FN (false negative) |
| Actual Negative | FP (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
| Metric | Question it answers | Formula |
|---|---|---|
| Accuracy | overall how often correct? | |
| Recall (sensitivity, TPR) | of actual +, how many found? | |
| Specificity (TNR) | of actual −, how many correct? | |
| Precision | of 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
For a fraud detector, which metric matters most and why — precision or recall?
- Hint: Cost of a false negative.
Answer
- Short answer: Recall (sensitivity) — a missed fraud (false negative) is far costlier than a false alarm (false positive), so you maximise the fraction of actual frauds caught.
- Why: Error asymmetry ➔ recall penalises misses; the tolerable error (FP) is what precision would protect.
Why can a 95%-accurate classifier still be useless?
- Hint: Class imbalance.
Answer
- Short answer: If 95% of cases are negative, always predicting “negative” scores 95% accuracy yet catches zero positives (recall 0); accuracy hides this.
- Why: Imbalance ➔ inspect recall/precision on the positive class, not overall accuracy; the honest baseline is the majority-class frequency, not .
Classification accuracy is computed on new data, not the training data. What would go wrong otherwise?
Answer
- Short answer: Training accuracy rewards memorisation — a model complex enough to fit every training label scores near and still fails on anything new.
- Why: Same generalisation problem as regression ➔ in-sample fit improves monotonically with complexity (Bias-Variance Tradeoff (Underfitting vs Overfitting)), so honest scoring needs held-out data, exactly as for the held-out NLL in Plug-in Prediction and Held-Out Evaluation.