Contents
02Accuracy lies
2.1The data and the model
Dal Pozzolo et al. (2015) released 284{,}807 transactions made by European cardholders over two days in September 2013, of which 492 (0.173\%) are fraud. To protect the cardholders, 28 of the features are principal components of the original variables, named V_1,\dots,V_{28}; the others are the time and the amount. Frauds are usually small: their median amount is 9.25, against 22.00 for legitimate payments (the currency is not given).
We do what a bank would do: train on the past and test on the future (Episode 11). Day 1 (144{,}786 transactions, 281 frauds) trains a logistic regression on V_1,\dots,V_{28} and \log(1+\text{amount}), standardized with day-1 statistics. Day 2 (140{,}021 transactions, 211 frauds) is the test set, untouched until the end. On the test day the prevalence, the share of transactions that are fraud, written \pi, is \pi=0.151\%, about 15 frauds in every 10{,}000 transactions (Figure 1a).
2.2The lazy model and the four boxes
A model that says “legitimate” every time is right on all 139{,}810 legitimate transactions and wrong on all 211 frauds: its accuracy is 139{,}810/140{,}021=99.85\%. Our model flags a transaction when its predicted fraud probability p is at least a threshold, written \tau; here \tau=0.5. It scores 99.90\%. A useless model and a useful one differ by five hundredths of a percentage point.
To see why, sort the predictions into the four boxes of the confusion matrix (Murphy, 2022, Table 5.3): rows are the truth, columns the decision (Figure 1b,c). Our model catches \mathrm{TP}=118 frauds, raises \mathrm{FP}=45 false alarms, misses \mathrm{FN}=93 frauds and lets \mathrm{TN}=139{,}765 legitimate payments through. Accuracy is
The true negatives are 99.8\% of the table. Whatever happens to the 211 frauds moves accuracy by at most 211/140{,}021=0.15 points, so accuracy is almost entirely a measure of how rare fraud is. This is sometimes called the accuracy paradox: when one class dominates, the trivial majority-class classifier is hard to beat on accuracy.
2.3Other rare positives
The same thing happens wherever the interesting class is rare. Fawcett (2006) notes that class skews of 10 to 100 to one are common in practice and that skews up to 10^6 have been reported. In information retrieval, Manning et al. (2008, p. 155) note that normally more than 99.9\% of the documents are irrelevant to a query, so a system that returns nothing is “accurate”; that is why retrieval has always been measured by precision and recall. In screening for a disease with prevalence 1\%, a test that always says “healthy” is 99\% accurate. In each case we need numbers that look at the rare class directly, and that is what the rest of this tutorial builds.
Pause and think. A quality inspector at a factory where 2 parts in 1{,}000 are defective reports 99.7\% accuracy. Is that good?
Show the answer
It is worse than doing nothing: declaring every part good is 99.8\% accurate. The inspector’s accuracy says nothing until we know how many of the defective parts were caught and how many good parts were rejected, which is exactly what precision and recall measure.