Lecture: Lecture 10 - Classification
Separate the model-building roles
The training set fits the model. A validation set can select an algorithm or tune hyperparameters. A test set is held back for the final performance estimate.
Holdout reserves a fixed partition, often appropriate for a large dataset. In k-fold cross-validation, the data is split into k folds. Train on k-1, test on the remaining fold, repeat for every fold and average the results. Stratified sampling keeps class proportions similar across partitions.
Confusion matrix
For a disease classifier:
| Predicted disease | Predicted healthy | |
|---|---|---|
| Actual disease | TP | FN |
| Actual healthy | FP | TN |
- TP: sick and correctly detected.
- TN: healthy and correctly cleared.
- FP: healthy but incorrectly flagged.
- FN: sick but missed.
Metrics
Accuracy = (TP + TN) / (TP + TN + FP + FN)
Precision = TP / (TP + FP)
Precision asks: among positive predictions, how many were correct?
Recall = TP / (TP + FN)
Recall asks: among actual positives, how many were found?
F-measure = 2 * precision * recall / (precision + recall)
F-measure balances precision and recall.
Why accuracy can mislead
Suppose a disease affects 100 of 10,000 patients. A model predicting healthy for everyone obtains 9,900/10,000 = 99% accuracy, but recall is 0%. For screening, missing a sick patient may matter more than investigating a false alarm, so recall and class-specific costs should be examined.
ROC curves
A classifier that outputs scores can be tested at several thresholds. A ROC curve plots true positive rate against false positive rate. The ideal point is (0, 1): no false alarms and all true positives. The diagonal represents random guessing.
Retrieval questions
Why must the test set be kept unseen? Reusing it to tune the model makes the final score optimistic.
When is recall more important than precision? When missing a positive case is particularly costly, such as an initial medical screening step.
Why is class distribution part of evaluation? A heavily imbalanced dataset can make overall accuracy look high even when the minority class is never detected.