Classical machine learningML 10

Evaluating Classifiers

A model that outputs a score or a probability only makes decisions once a threshold is chosen, and every threshold trades one kind of mistake for another. This demo looks at a fictional blood test from the point of view of a clinic: how many sick people does it catch, how many healthy people does it alarm, and what does a positive result actually mean? The second part shows cross-validation, the standard way to estimate how well a model will do on new data and to choose its settings.

1 · Thresholds, errors and the ROC curve

test results: 150 healthy, 150 diseaseddrag to move the threshold
solid bars: the people the threshold gets wrong
ROC curveclick to choose a point
dot: the current threshold · diagonal: a coin toss

Confusion matrix

What a result means in practice

aqua: healthy · orange: diseased · the sample is half and half, so its PPV and NPV describe a population where half the people tested are ill; the panel on the right recalculates them for the prevalence you choose

2 · Cross-validation: choosing a tree's depth

The rounds orange: held out for testing in that round · number: test accuracy

Accuracy by depth

data: the electrolytes example from the decision tree demo (110 points) · each depth is trained and tested k times, once per fold · dashed orange: the mean ± one standard deviation across folds, a rough guide that understates the real uncertainty

Sensitivity, specificity and the threshold

Sensitivity is the share of diseased people the test calls positive; specificity is the share of healthy people it calls negative. Yerushalmy (1947) popularised both terms while comparing how radiologists read chest X-rays. Lowering the threshold catches more disease but alarms more healthy people, and raising it does the reverse. Where to put it depends on the cost of each mistake: a screening test, where a missed case is costly and a false alarm only leads to a second test, favours sensitivity; a confirmatory test before a risky treatment favours specificity.

The ROC curve and AUC

The ROC curve, a term borrowed from radar engineering, plots sensitivity against the false positive rate (1 − specificity) for every possible threshold at once, so it describes the test itself rather than one choice of threshold. The area under it, the AUC, is the probability that a randomly chosen diseased person scores higher than a randomly chosen healthy one (counting ties as half; Hanley & McNeil, 1982): 0.5 is no better than chance, 1 is perfect separation. Move the separation slider to see the curve bow out towards the top-left corner as the groups pull apart.

Prevalence and predictive values

Sensitivity and specificity do not depend on how common the disease is, but what a positive result means does. The positive predictive value (PPV) is the chance that someone who tests positive really has the disease, and it falls steeply as the disease gets rarer, because the few true positives are swamped by false positives from the large healthy majority. Set the prevalence to 1% to see a test that is right most of the time produce mostly false alarms. This is why screening programmes for rare conditions follow a positive result with a more specific test, and why accuracy alone is misleading when the classes are unbalanced.

Cross-validation

Judging a model on the data it was trained on rewards memorising: the deepest tree scores best on its own training data. A single held-out test set avoids that but wastes data, and with small datasets the result depends on which points happened to land in it. k-fold cross-validation splits the data into k parts, trains on k − 1 of them and tests on the remaining one, k times over, so every point is used for testing exactly once (cross-validation: Stone, 1974; Geisser, 1975). The average estimates performance on new data, and the spread across folds gives a rough sense of how much it varies. Only a rough one: the folds share most of their training data, so their spread tends to understate the real uncertainty, and there is no unbiased way to estimate it from a single run (Bengio & Grandvalet, 2004). Choosing the depth with the best cross-validated accuracy, as here, is how settings are usually tuned; a final, untouched test set then gives an honest score for the chosen model.

References

  1. Yerushalmy, J. (1947). Statistical problems in assessing methods of medical diagnosis, with special reference to X-ray techniques. Public Health Reports, 62(40), 1432–1449. doi.org/10.2307/4586294
  2. Hanley, J. A., & McNeil, B. J. (1982). The meaning and use of the area under a receiver operating characteristic (ROC) curve. Radiology, 143(1), 29–36. doi.org/10.1148/radiology.143.1.7063747
  3. Altman, D. G., & Bland, J. M. (1994). Diagnostic tests 1: sensitivity and specificity. BMJ, 308(6943), 1552. doi.org/10.1136/bmj.308.6943.1552
  4. Altman, D. G., & Bland, J. M. (1994). Diagnostic tests 2: predictive values. BMJ, 309(6947), 102. doi.org/10.1136/bmj.309.6947.102
  5. Fawcett, T. (2006). An introduction to ROC analysis. Pattern Recognition Letters, 27(8), 861–874. doi.org/10.1016/j.patrec.2005.10.010
  6. Geisser, S. (1975). The predictive sample reuse method with applications. Journal of the American Statistical Association, 70(350), 320–328. doi.org/10.2307/2285815
  7. Bengio, Y., & Grandvalet, Y. (2004). No unbiased estimator of the variance of k-fold cross-validation. Journal of Machine Learning Research, 5, 1089–1105. jmlr.org/papers/v5/grandvalet04a.html
  8. Stone, M. (1974). Cross-validatory choice and assessment of statistical predictions. Journal of the Royal Statistical Society, Series B, 36(2), 111–133 (with discussion, 133–147). doi.org/10.1111/j.2517-6161.1974.tb00994.x