Model Testing
Evaluating a model
Start from the confusion matrix (TP, FP, FN, TN). Accuracy alone is misleading under imbalance: a 99:1 dataset yields 99% accuracy by always predicting the majority class (the accuracy paradox). Instead use precision (of predicted positives, how many are right), recall/sensitivity (of actual positives, how many were found), specificity, F1 (harmonic mean of precision and recall), and threshold-independent measures such as ROC-AUC, or PR-AUC when positives are rare.
Generalisation
Overfitting = good on training data, poor on unseen data. Underfitting = poor everywhere. Controls: hold-out test set, k-fold cross-validation, regularisation, early stopping, learning curves. The test set is touched once, at the end.
Beyond accuracy
- Robustness testing: noise, blur, paraphrasing, out-of-distribution inputs, adversarial examples.
- Bias/fairness testing: performance disparity across subgroups; disparate impact.
- Metamorphic testing: when no oracle exists, assert relations (e.g. adding imperceptible noise to an image should not change the label).
- Coverage measures for neural networks (neuron/layer coverage) exist but are not reliable sufficiency criteria - treat them as heuristics.
Trap list
- Reporting accuracy on imbalanced data.
- Choosing the decision threshold on the test set.
- Comparing two models on a single run without considering variance/statistical significance.
- Assuming high training accuracy indicates a good model.
Rule of thumb
Pick the metric from the cost of errors, not from convenience: for fraud screening where missing fraud is costly, optimise recall and accept lower precision; for spam filtering where false positives annoy users, weight precision.