Accuracy and Error Measures
1. Classifier Accuracy, Error Rate and the Confusion Matrix
For a test set of tuples (binary classes: positive P, negative N):
Confusion / contingency matrix
| Predicted Positive | Predicted Negative | Total | |
|---|---|---|---|
| Actual Positive | TP (true positive) | FN (false negative) | P |
| Actual Negative | FP (false positive) | TN (true negative) | N |
| Term | Definition |
|---|---|
| Sensitivity / Recall / True Positive Rate | |
| Specificity / True Negative Rate | |
| Precision | |
| F1 / F-score | |
| False Positive Rate | specificity |
| False Negative Rate | sensitivity |
Worked example — 200 test tuples, 120 positive, 80 negative. Classifier predicts 105 positive of which 95 are correct, and 95 negative of which 70 are correct:
2. Which Measure to Use?
Accuracy alone is misleading with imbalanced classes. For 1000 tuples with 990 negative and 10 positive, a "always negative" classifier has 99% accuracy but 0% recall and 0% F1.
- Rare disease / fraud detection → maximise recall, accept lower precision.
- Spam filtering / credit approval → emphasise precision.
- Balanced view → F1 or AUC.
- Cost-sensitive → weighted error:
3. ROC Curves and AUC
Plot TPR (sensitivity) against FPR (1 − specificity) while varying the classification threshold; a perfect classifier is the point (0,1) and a random guess is the diagonal.
TPR
1.0 |---------___------ model B (better, larger AUC)
| __/
| _/ ... model A (moderate)
| _/ /
0.5 | / / ---- random classifier (diagonal)
|/ /
0.0 +-------------------- FPR
0.0 0.5 1.0
Other tools: precision-recall curve, lift chart (cumulative gain), cost curve.
4. Measures for Numeric Predictors
MSE is sensitive to outliers (squared); MAE is more robust. RMSE has the same unit as the target, so it is more interpretable.
5. Estimators of Accuracy — Sampling and Confidence Intervals
Accuracy measured on a finite test set is only an estimate. If the model makes correct predictions out of independent trials, the error follows a binomial distribution whose standard deviation is
% confidence interval for accuracy:
Numerical example — accuracy 0.85 on 200 tuples: ; the 95% CI is , i.e. [80.1%, 89.9%]. Larger test sets give tighter intervals ().
Comparing two classifiers honestly is harder than it looks — the tests are not independent (same training/test data), so use paired methods:
| Method | Idea |
|---|---|
| McNemar's test | Compares the two classifiers on a table of disagreement counts ; with 1 d.o.f., or an exact binomial test |
| -fold cross-validated paired -test | Compare the per-fold differences of error rates |
| Sign test / Wilcoxon signed-rank | Non-parametric comparisons |
6. Occam's Razor, Bias–Variance and Model Cost
Between two models with equal test error, prefer the simpler one (fewer parameters/rules/leaves) — it is more likely to generalise.
Expected error, or a pessimistic estimate used for pruning a tree (with , = tuples at the node, = number of leaves):
7. Other Useful Measures
| Measure | Formula | Note |
|---|---|---|
| Lift | >1 means the rule improves on the base rate | |
| Kappa (Cohen) | Agreement corrected for chance | |
| Geometric mean | Robust for imbalance | |
| Matthews correlation (MCC) | Balanced single number (−1..+1) | |
| Brier score | Calibration of predicted probabilities | |
| Log loss | Penalises confident wrong probabilities |
8. Exam Points
- Build a confusion matrix from given data and compute accuracy, error, sensitivity, specificity, precision, F1 — 10 marks (very frequent numerical).
- Explain ROC and AUC with a sketch — 5 marks.
- Compute a confidence interval for accuracy and interpret it — 5 marks.
- Explain MSE, RMSE, MAE and for predictors — 5 marks.
- Why is accuracy misleading for imbalanced data? — 3 marks.