Articles

How do you calculate precision, recall and F1 for a default model?

The confusion matrix of a credit scorecard, cut-off by cut-off, and why the threshold that maximises F1 is not the one that maximises profit.

For a credit default model, treat a declined application as a predicted default. Precision is the share of declined applicants who would have defaulted, recall the share of all defaulters the cut-off declines, and F1 is their harmonic mean, 2PR / (P + R). On an illustrative book of 10,000 applications, a cut-off at 540 points gives precision of 16.4 per cent, recall of 56.1 per cent and an F1 of 0.254. F1 peaks one band lower, at 520, and that cut-off earns 2.11 million less.

Worked in full in Machine Learning for Finance by Julian R. Sterling, with every figure reproduced in a free workbook.See the book on Amazon →

The assumptions

The book below is illustrative: 10,000 applications in ten score bands, 672 of which went bad, a bad rate of 6.72 per cent. The unit economics are those derived in Machine Learning for Finance: a loan that performs earns 6,982, one that defaults loses 77,785.

Applications and bads by score band
Score bandApplicationsBadsBad rate
below 50060015025.0%
500-51980012816.0%
520-5399009911.0%
540-5591,000808.0%
560-5791,100666.0%
580-5991,200544.5%
600-6191,200423.5%
620-6391,100282.5%
640-6591,100171.5%
660 and above1,00080.8%
Total10,0006726.72%

Step 1: the confusion matrix at one cut-off

Decline everything below 540 points: the first three bands, 2,300 applications. The positive class is "default", so the four cells are:

True positives (bads declined) = 150 + 128 + 99 = 377

False positives (goods declined) = 2,300 − 377 = 1,923

False negatives (bads approved) = 672 − 377 = 295

True negatives (goods approved) = 9,328 − 1,923 = 7,405

Step 2: precision, recall and F1

Precision = TP / (TP + FP) = 377 / 2,300 = 16.39%

Recall = TP / (TP + FN) = 377 / 672 = 56.10%

F1 = 2 × P × R / (P + R) = 2 × 16.39% × 56.10% / 72.49% = 0.2537

Excel, cut-off in band k: =SUM(Bads1:Badsk)/SUM(Apps1:Appsk) for precision, =SUM(Bads1:Badsk)/SUM(Bads) for recall

A precision of 16.39 per cent looks poor to anyone used to classification benchmarks. In credit it is normal: with a 6.72 per cent base rate, even a good model declines several good applicants for every bad one it stops.

Step 3: every cut-off, and what each one earns

Profit counts approved goods at 6,982 and approved bads at minus 77,785.

Declining every band below the cut-off
Cut-offDeclinedPrecisionRecallF1AccuracyProfit, million
none00.0%0.0%0.00093.3%12.86
50060025.0%22.3%0.23690.3%21.38
5201,40019.9%41.4%0.26884.8%26.65
5402,30016.4%56.1%0.25477.8%28.76
5603,30013.8%68.0%0.23069.4%28.55
5804,40011.9%77.8%0.20659.7%26.47
6005,60010.3%85.9%0.18448.8%22.67

Three metrics, three answers. Accuracy is highest when nothing is declined, 93.28 per cent, because predicting "good" for everyone is right for 93.28 per cent of the book. F1 is highest at 520, 0.2683. Profit is highest at 540, 28.76 million, 2.11 million more than the F1 choice.

Why F1 picks the wrong cut-off

F1 treats a declined good and an approved bad as roughly equal errors. The economics do not: one default costs 77,785, the profit of 11.14 performing loans. The correct rule is to decline a band when its bad rate exceeds the break-even:

Break-even bad rate = profit on a good / (profit on a good + loss on a bad)

= 6,982 / (6,982 + 77,785) = 6,982 / 84,767 = 8.2367%

The 520-539 band runs at 11.0 per cent, above break-even, so it should be declined; F1 keeps it. Declining it rejects 801 good loans and stops 99 bad ones, worth 2,108,133. The 540-559 band, at 8.0 per cent, sits just below break-even and should be approved, which is what the profit column shows: moving to 560 costs 0.2 million.

The break-even depends on loss given default and margin, not on the model. If losses rise, the break-even bad rate falls and the cut-off should move up. Precision and recall do not move at all.

The common mistake

Reporting F1 or accuracy as the model's performance and choosing the threshold that maximises it. Both are useful for comparing models at a fixed approval rate; neither should set the cut-off. Ranking quality across all cut-offs is what Gini and KS measure, in how to calculate Gini and KS for a scorecard; what a cut-off left in the wrong place costs is in what an unchanged score cut-off costs.

Takeaway

The unit economics, the break-even and both profit grids are live in the free workbook for this case.

Questions readers ask

What is the positive class in a credit default model?

Default, so a declined application is a predicted positive. With 672 bads in 10,000 applications, a cut-off declining 2,300 applicants that catches 377 bads has 377 true positives, 1,923 false positives and 295 false negatives, giving precision of 16.39 per cent and recall of 56.10 per cent.

Why is accuracy misleading for a credit scorecard?

Because defaults are rare. On a book with a 6.72 per cent bad rate, approving everybody is 93.28 per cent accurate and catches no defaulter. Every cut-off that declines anyone lowers accuracy, even the one that lifts profit from 12.86 million to 28.76 million in the illustrative case.

How do you choose a credit score cut-off instead of maximising F1?

Decline a score band when its bad rate exceeds the break-even, profit on a good divided by the sum of that profit and the loss on a bad. With 6,982 earned and 77,785 lost, the break-even is 8.2367 per cent. The 520-539 band at 11.0 per cent is declined, which F1 would keep, adding 2,108,133 of profit.

Read the whole case

This article is one calculation from Machine Learning for Finance. The book takes the same case from first principles to the decision, chapter by chapter, and every figure it prints is a live formula in the free companion workbooks.

Get the book on Amazon →Free companion files

Also on Amazon UK · Amazon Germany · Amazon France · Amazon Canada

Also on this site

Reading guide: corporate finance, valuation and markets → · All 1340 articles →

If this book helped, or didn’t, a few lines on Amazon are worth more than they look: they are what the next reader goes on. Write a review. The workbook stays free either way.