ML1: Thinking in machine learning

Lesson 4 of 5 ยท reading 15โ€“25 minutes; practice and project time is on the module page

Baselines first

๐ŸŽฏYou'll be able to

Measure a "do nothing" baseline and a simple rule, so you know what a model has to beat.

๐Ÿ The everyday picture

Before buying an expensive water filter, you'd check how clean the tap water already is. A baseline is the tap water: the result you get with no model at all, or with the simplest rule a sensible person would try.

๐Ÿ“˜What it really is

๐Ÿ“A worked example

Input: the June parcels from the kit.

june = df[df['booked_at'].str.startswith('2026-06')]
print(len(june), round(june['late'].mean(), 4))
print('always on time, accuracy:', round(1 - june['late'].mean(), 4))
rule = june['address_quality'] < 0.5
caught = (rule & (june['late'] == 1)).sum()
print('rule flags', rule.sum(), 'recall', round(caught / june['late'].sum(), 4), 'precision', round(caught / rule.sum(), 4))

Expected output: 2221 0.0968; "always on time" is 90.32% accurate but catches no late parcels; the address rule flags 246 parcels, with recall 0.6093 and precision 0.5325. So a model must do better than "catch 61% of late parcels while 53% of the calls are useful". The kit's model, at its chosen threshold, has precision 0.6647 and recall 0.5349 on June: more useful calls, but it catches fewer late parcels than the rule. Which is better depends on the cost of calls and of late parcels (ML4 Lesson 4).

๐ŸŒWhere it's used

๐Ÿ“Case scenario

A food delivery company spent two months on a model to predict which orders would be cancelled. When someone finally compared it with the rule "flag orders from new customers paying cash at night", the rule caught nearly as many cancellations and was easier to explain. The team kept the rule and moved the model work to a question the rule couldn't answer.

๐Ÿ–ฑ๏ธTry it

Try the rule "address score below 0.5 or remote destination" on June. Success: it catches more late parcels (recall about 0.79) but precision falls to about 0.40, so more calls are wasted.

โš ๏ธCommon mistakes

๐Ÿ› ๏ธFor your project

Project 1's test 4 checks that metrics.json reports a baseline on June; test 5 checks that the model clearly beats it.

โœ…Quick check

Why is "always on time" 90% accurate in June but useless?

Show the answer

Because about 90% of parcels are on time anyway, and it catches no late ones.

What makes a good simple-rule baseline?

Show the answer

Something a sensible expert would try first, measured on the same data as the model.

โ† PreviousData as arrays: X, y and one row per prediction
ProLearners Assist