← Back to the track

Learn machine learning · part 1 · session 5

Accuracy lies

Ninety-five repaid against five not, a price on each of the two mistakes, and one slider. The threshold with the best accuracy is about to be the most expensive one on the page.

After this session you will be able to price two kinds of mistake and pick a threshold that minimises cost instead of error count.

metric.costSession 1.5About 25 minutesYour check: reach the stated target

Total cost at or below 410 on the audit set, and the follow-up reason chosen correctly.

01 · The question

I have deliberately rebuilt this held-out set so that only 5 in 100 are defaults, because that lopsidedness is where stops being informative. Approving every application scores 0.95 and misses every default. So put a price on the two mistakes instead. In this exercise, approving an application that is not repaid costs ten synthetic cost units; refusing one that would have been repaid costs one. Those numbers are invented for the exercise and describe no real lender. Move the , watch the four cells of the table, and find the cheapest place to stand. The four metrics you computed by hand in 1.4 sit beside the matrix and move with it, so you can see which of them the cheapest threshold sacrifices.

A model you have not built yet has given every application a repayment score between 0 and 1; higher means more likely to be repaid. Here the 1,000 applications are sorted by that score and cut into ten equal groups of 100, riskiest group first.

syntheticseed 7 · 1,000 rows
The audit set in ten score deciles, riskiest first
Score decile, riskiest firstRowsNot repaidLocal not-repaid rateUpper score boundary
11001818 per cent0.41
21001111 per cent0.53
310077 per cent0.61
410055 per cent0.68
510044 per cent0.74
610022 per cent0.79
710011 per cent0.84
810011 per cent0.89
910011 per cent0.94
1010000 per cent1.00
Synthetic, seed 7, resampled to a 95 to 5 balance for this exercise.

02 · Predict

Before anything runs

The threshold with the highest accuracy will also have:

The threshold with the highest accuracy will also have:

Choose something first.

03 · Try it

Sliding the line across 1,000 applications

syntheticseed 7 · the audit set above

Threshold 0.00: 0 refused, cost 500, accuracy 0.950. Approve everything. This is also the most accurate the sweep gets.

The cheapest place to stand is not the most accurate place to stand.

Move the threshold

computed in this browserseed 7 · 1,000 audit rows

An application scoring at or below the threshold is refused. Everything above it is approved.

0.00 to 1.00

0.00 approves every application. 1.00 refuses every application.

computed in this browserseed 7 · 1,000 audit rows

A positive prediction here means: refuse this application, the exercise's name for this one will not be repaid

Confusion matrix. Predicted positive, actually positive: 18. Predicted positive, actually negative: 82. Predicted negative, actually positive: 32. Predicted negative, actually negative: 868.
Actually positiveActually negative
Predicted positiverefused and not repaid18no cost: the refusal was rightrefused and repaid821 unit each
Predicted negativeapproved and not repaid3210 units eachapproved and repaid868no cost: the approval was right

Predicted positive, actually positive: 18. Predicted positive, actually negative: 82. Predicted negative, actually positive: 32. Predicted negative, actually negative: 868.

Synthetic, seed 7, resampled to a 95 to 5 balance for this exercise.
Accuracy
0.886of everything, how much was right
Precision
0.180of the rows you flagged, how many were real
Recall
0.360of the rows that were real, how many did you flag
F1
0.240the balance of the last two, in one number

Total cost, in synthetic cost units invented for this exercise

done

402

10 × 32 approved and not repaid, plus 1 × 82 refused and repaid. The target for this session is 410.

These prices are invented for the exercise and describe no real lender.

Threshold 0.50. Approved 900, of which 868 repaid and 32 not repaid. Refused 100, of which 82 repaid and 18 not repaid. Accuracy 0.886, precision 0.180, recall 0.360, F1 0.240. Cost 402.

A whole number, matched exactly.

Attempts: 0

A whole number, matched exactly.

Attempts: 0

Why the accuracy-best threshold was the worst by cost

Why the accuracy-best threshold was the worst by cost

04 · Compare

The verdict appears once you have recorded a position in beat two. It names what the accuracy-best threshold costs, which is the thing beat two asks you to call.

05 · Check your understanding

Your check: reach the stated target

not yet

Total cost on the audit set at or below 410, and the follow-up reason selected correctly. Approving everything costs 500 and refusing everything costs 950, so neither of those passes.

Not met yet. Keep working the session.

  • done Cost at or below 410: you are at 402, and the cheapest you have reached is 402.
  • not yet The follow-up reason chosen correctly.

Save your takeaway

Ask for a hint

Rungs open as you run the session, not as time passes. You have run it 0 times.

1. A question: available after 3 evaluated runs.

2. A narrowing: available after 5 evaluated runs.

3. A worked fragment, on a different example: available after 7 evaluated runs.

4. The answer: available after 9 evaluated runs.

Your takeaway

Edit it into your own words, or keep the line as it is.