Skip to content
mentoor

Topic 1 of 5 · 5 min read

Framing a prediction problem as features and labels

Goal: Turn a business question into a supervised problem by naming the label, the features available at prediction time and what one example is.

Supervised learning starts with a table: one row per example, columns the model may look at (features), and one column it must predict (the label). Most failed projects fail here, before any model is chosen.

Check yourself · 1 of 3

In a supervised learning table, what is the label?

Choose one answer

Why it matters

A business question such as "which customers will leave?" is not yet a machine-learning problem. The model cannot be trained until you decide what one row is, what the label means exactly, and which columns will really exist on the day you use the prediction. A model trained on a badly framed table can score well in a notebook and be useless in production.

How to frame it

  1. Pick the unit. One row per customer, per order, per support ticket? Write it as "one example is a customer on the first day of a month".
  2. Define the label precisely. "Churned" becomes "cancelled within 30 days after the example date". Include the time window. A label with no window is not measurable.
  3. Choose the task type. A label with a few categories (churned yes or no, ticket topic) is classification. A label that is a number (price, delivery minutes) is regression.
  4. List features and ask the timing question for each. Would this value be known at the moment of prediction? Anything recorded after the outcome is leakage: the model learns to read the answer instead of predicting it.
  5. Check that labels exist. Someone or something must have recorded the outcome for past examples. If not, you need labelling work before you need a model.

Before and after

Before: "Predict late deliveries using order data." After:

Unit:      one delivery
Label:     is_late = delivered more than 20 minutes after the promised time (classification)
Features:  distance_km, restaurant_prep_avg, hour_of_day, weather_at_order_time
Not usable: driver_rating_for_this_trip (written after delivery), refund_issued

The weak version has no label, no unit and no timing rule. The fixed one can be turned into a dataframe and a y column.

What goes wrong

  • Leakage. A column such as refund_issued or account_closed_date is filled in only after the outcome. Validation scores look excellent and the live model collapses.
  • Wrong unit. If the same customer appears in many rows, rows are not independent. Later splits then put one customer on both sides and inflate the score.
  • Fuzzy label. Two teams mean different things by "churn", so the model learns an average of both definitions and satisfies neither.
  • Wrong task type. Predicting an exact number when the product only needs "above or below a threshold" makes the problem harder than it has to be.

The scikit-learn convention is a feature matrix X (rows by columns) and a label vector y. If you cannot describe both in one sentence each, stop and fix the framing.

Examples

Churn question turned into a training table

Question: "Which subscribers will leave?"

Part Decision
Unit One subscriber on the first day of a month
Label cancelled_within_30d (yes or no), so classification
Usable features plan, months_active, logins_last_30d, support_tickets_last_30d
Excluded cancellation_reason and last_invoice_status, both written after the cancel

Each feature was checked against the question "do we know this on the first of the month?"

Same data, two tasks

A delivery table can predict delivery_minutes (regression) or is_late (classification). If dispatch only needs a warning flag, the classification framing is simpler to evaluate and to explain. If a customer-facing app shows an estimated time, regression is the better fit.

Key points

  • Every supervised problem is a table with one row per example, feature columns and one label column.
  • The label needs a precise definition including its time window, or it cannot be measured.
  • A feature is usable only if its value is known at the moment the prediction is made.
  • A label with categories is classification; a label that is a number is regression.
  • Leakage, a feature recorded after the outcome, is the most common reason an excellent score fails in production.

Common mistakes

  • Including a column that is only filled in after the outcome, then trusting the high validation score.
  • Defining the label loosely ("churned") with no time window, so different people label the same customer differently.
  • Treating several rows of the same customer as independent examples.
  • Choosing regression when the decision only needs a yes or no.

Check yourself · 2 of 3

A team predicts which orders will be refunded. One proposed feature is refund_reason. What is wrong with it?

Choose one answer

Check yourself · 3 of 3

The product needs to know whether a package will arrive more than one day late, so it can warn the customer. How should the problem be framed?

Choose one answer

Practice items, not counted towards your mastery.

Start here