2.5 Prediction, classification, and error
Prediction, classification, and error
A model makes predictions. The crucial follow-up question is always: how good are they? Measuring error correctly is as important as building the model, and a single misleading number has sunk many AI projects.
Error and loss
During training, the model minimizes a loss — a number capturing how far its predictions are from the truth. After training, we evaluate it on held-out data with metrics that humans can interpret. For classification, the simplest is accuracy: the fraction of predictions that are correct.
Why accuracy can lie
Accuracy is dangerously misleading when the categories are imbalanced. Suppose 1 in 1,000 transactions is fraud. A model that simply predicts "not fraud" every time is 99.9% accurate — and completely useless, because it never catches fraud. To see past this, we break errors into types.
Precision and recall
Imagine a model flagging fraud. There are two kinds of mistake:
- A false positive — flagging a legitimate transaction as fraud.
- A false negative — missing an actual fraud.
From these we get two metrics. Precision asks: of the things the model flagged, what fraction were truly positive? (High precision = few false alarms.) Recall asks: of all the truly positive things, what fraction did the model catch? (High recall = few misses.) There is usually a trade-off: catching more fraud (higher recall) often means more false alarms (lower precision). Which matters more depends entirely on the cost of each error.
A worked example
For a cancer screening test, a false negative — telling a sick patient they are healthy — is catastrophic, while a false positive merely triggers a follow-up test. So you tune the model for high recall, accepting more false alarms to miss as few real cases as possible. For a spam filter, the reverse: a false positive that deletes an important email is worse than letting one spam through, so you favor precision. The "best" model is meaningless without knowing which error you are most afraid of.
