How a machine learns, and how it fools itself
Training, testing, overfitting and data leakage, with a model you can bend until it breaks.
Supervised learning is the commonest kind in medicine. You give the computer many examples where the answer is known (X-rays labelled “pneumothorax” or “normal”) and it adjusts itself until its guesses match the labels as closely as possible. The gap between its guess and the true label is the error, and training is the process of shrinking that error.
The trap is that a flexible enough model can shrink the error to zero by memorising the training cases, noise and all. It then does badly on new patients. Try it:
This is why every honest study splits its data three ways. The training set teaches the model. The validation set is used to tune it (choose the flexibility, the cut-off). The test set is locked away and used once, at the end, to report performance.
If the same patient appears in both training and test sets (say, two X-rays from one admission), the model can recognise the patient rather than the disease, and the test score looks better than it is. Splits must be done at patient level. Other leaks: a variable that is only recorded after the diagnosis (an antibiotic order used to “predict” sepsis), or a scanner label burned into the image.
Watch
Check yourself
Educational material, not clinical advice. Interactive numbers are teaching examples unless a source is named.