ML1: Thinking in machine learning

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Framing the problem: target, inputs and the moment of prediction

🎯You'll be able to

Write down exactly what is predicted (the target), for which unit, at what moment, and from which inputs.

🏠The everyday picture

A weather forecast for tomorrow can only use what is known today. If the forecaster could read tomorrow's newspaper, the forecast would look perfect and be useless. A model has the same limit: it can only use what is known at the moment it makes its guess.

📘What it really is

📝A worked example

Input: the columns of raw/shipments.csv.

import pandas as pd
df = pd.read_csv('raw/shipments.csv', dtype={'customer_phone': str})
print(df.shape)
print(df.columns.tolist())

Expected output: (13410, 17), then 17 column names. Sort them into four groups:

Group Columns
Identifier shipment_id, booked_at (used to build the hour and weekday)
Known at booking (features) origin_hub, dest_zone, distance_km, weight_kg, service, pickup_slot, address_quality, hub_load, payment, promised_days
Known only after delivery delivered_at, delay_hours
Personal, not used customer_name, customer_phone
Target late

The kit's dakdost/features.py keeps 12 features: the 10 known at booking plus the booking hour and weekday.

🌍Where it's used

📝Case scenario

A hospital's model to predict which patients would be readmitted looked excellent in testing. It used the number of follow-up appointments booked, which is known only after discharge. At the moment of discharge, when the prediction was needed, that column was always zero, and the model was much weaker in use.

🖱️Try it

For a ride-hailing app that wants to predict, when a ride is requested, whether the driver will cancel: write the unit, the target, the moment of prediction, four features and two columns that would be leakage. Success: the leakage columns are only known after the request, such as the actual pickup time or the cancellation reason.

⚠️Common mistakes

🛠️For your project

Project 1's first test checks that the saved model lists its features and that none of them is known only after delivery or personal.

✅Quick check

What is the moment of prediction for DakDost's model?

Show the answer

At booking, before the parcel moves.

Why is delay_hours not a feature?

Show the answer

It's known only after delivery, so it can't be used at booking.

← PreviousWhen machine learning is the right tool
ProLearners Assist