ML1: Thinking in machine learning
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
-
The unit of prediction is what one guess is about: one parcel, one customer, one day at one hub. It decides what one row of your data must be.
-
The target (also called the label, or
y) is what you predict. Define it exactly: DakDost'slateis 1 if the parcel was delivered after the promised date shown at booking, otherwise 0. -
The moment of prediction is when the guess is made. DakDost predicts at booking, before the parcel moves.
-
Features (the inputs, or
X) are what is known at that moment: zone, distance, weight, service, pickup slot, the address checker's score, how busy the hub is, payment type and the promised days. -
Not features: anything known only later (
delivered_at,delay_hours) and anything personal that the decision shouldn't depend on (customer_name,customer_phone). Using later information is called leakage (ML2 Lesson 2). -
The action is what happens after the guess: the hub team calls flagged customers to check the address. Write it down; it decides which mistakes matter most (ML4).
📝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
- Lending: predicting at application time whether a loan will be repaid, using only what the application and history show then.
- Retail: predicting next week's sales for each shop, from sales up to this week.
- Customer support: predicting at arrival whether an email is urgent, from its text and the customer's plan.
📝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
- A vague target. Sign: two people count "late" differently. Fix: write the exact rule, including the promised date it compares with.
- Features from the future. Sign: test scores look too good. Fix: for each column, ask "would I know this at the moment of prediction?".
- Personal data as features by default. Sign: names or phone numbers in the model's inputs. Fix: leave them out unless there's a clear, lawful reason (ML7).
🛠️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.
