From Business Question to Learning Task
Turn a vague business goal into a precise learning task: name the decision, the unit and time of prediction, the target and the features that exist at that time, and choose between supervised, unsupervised, semi-supervised, self-supervised and reinforcement learning.
Contentsand lesson path
On this page
- Why it matters
- Six questions that define a learning task
- Building a label at the prediction time
- Five learning paradigms
- Check your understanding
- Apply it
- Review prompt
Lessons of Machine Learning Fundamentals
- From Business Question to Learning Task Concept · 20 min
- The Estimator Contract: fit, predict, score Concept · 15 min
- Lab: Baselines First with Dummy, Linear and Neighbour Models Lab · 30 min
- Underfitting, Overfitting and Learning Curves Concept · 20 min
- Worked Example: Taming a Polynomial Fit with Ridge, Lasso and Elastic Net Worked example · 25 min
- Check: Framing, Baselines and Generalization Knowledge check · 8 questions
What you will learn
- Frame a business question as a learning task, choosing the paradigm (supervised, unsupervised, semi- or self-supervised, reinforcement) and naming the target, features, unit of prediction and how predictions will be acted on.
Prerequisites: Data Handling
01. Why it matters
Most machine learning projects that fail do not fail because of the algorithm. They fail because the model answers a different question from the one the business needed answered. A churn model that scores customers once a year cannot help a team that calls customers every month. A model that predicts late deliveries using the time a parcel was scanned at its destination looks brilliant offline and is useless in practice, because that scan happens after the decision it was meant to inform.
Problem framing is the step that prevents this. It turns a business goal ("fewer cancellations") into a learning task precise enough to build and evaluate: what exactly is predicted, for which unit, at what moment, from which inputs, and what someone will do with the answer. It also decides which family of machine learning fits, because the data you have (labels or no labels, a fixed dataset or an environment that reacts) narrows the choice before any code is written.
This lesson gives you a framing checklist, shows how to build a label correctly with a small pandas example, and explains the five learning paradigms with a runnable semi-supervised demo. The code uses Python 3.12, pandas 3.1 and scikit-learn 1.9.
02. Six questions that define a learning task
Start from the decision, not from the data. Answer these six questions in writing before you train anything.
- What decision will the prediction change, and who acts on it? For example: the retention team offers a discount to some customers. If no action follows a prediction, there is no reason to build the model.
- What is the unit of prediction? One prediction per customer, per order, per parcel, per support ticket? The unit must match the thing the action applies to. A per-region forecast cannot tell the team which customer to call.
- When is the prediction made? The prediction time is the moment the model runs, such as "the first day of each month" or "when the parcel leaves the depot". Only information that exists at that moment can be a feature.
- What is the target? The target (or label) is the value the model learns to predict. Define it exactly, with a time window: "cancels within 30 days after the prediction time", not "churns".
- Which features are available at prediction time? A feature is an input the model uses. Any field recorded after the prediction time, or caused by the outcome itself, is leakage: it makes offline scores look excellent and cannot exist when the model runs.
- How will success be measured, and against what baseline? Name the metric (for example, the share of real cancellations among the 200 customers called) and the simple rule the model has to beat, such as "call the customers with the most support tickets".
The answers depend on each other. Changing the action from "send an email" to "phone a customer" might change the unit (household instead of account), the time (daily instead of monthly) and the metric (precision in the top 200 instead of overall accuracy).
03. Building a label at the prediction time
Here is the framing for a subscription business. The decision: on 1 July, the retention team chooses whom to contact. The unit: one active customer. The target: 1 if the customer cancels within 30 days after 1 July, otherwise 0. The features: only facts known on 1 July, such as tenure and support tickets raised before July. The script turns a subscription table into training rows that follow exactly this framing.
import pandas as pd
# One row per subscription; cancelled_at is empty while the customer stays
subs = pd.DataFrame({
"customer": ["ana", "ben", "chen", "dina", "eli"],
"signed_up": pd.to_datetime(["2026-01-10", "2026-03-02", "2026-04-20",
"2026-05-15", "2026-06-01"]),
"cancelled_at": pd.to_datetime(["2026-07-12", None, "2026-08-25",
"2026-07-03", None]),
"support_tickets_before_jul": [0, 4, 1, 2, 0],
})
cutoff = pd.Timestamp("2026-07-01") # the day we would make predictions
horizon = pd.Timedelta(days=30) # the window the action can affect
active = subs[subs["cancelled_at"].isna() | (subs["cancelled_at"] >= cutoff)].copy()
active["tenure_days"] = (cutoff - active["signed_up"]).dt.days # known at cutoff
active["label"] = (active["cancelled_at"] < cutoff + horizon).astype(int)
print(active[["customer", "tenure_days", "support_tickets_before_jul", "label"]]
.to_string(index=False))customer tenure_days support_tickets_before_jul label
ana 172 0 1
ben 121 4 0
chen 72 1 0
dina 47 2 1
eli 30 0 0Three details carry the framing. Dina cancelled on 3 July, after the cut-off, so she is still an active customer on 1 July and her label is 1. Chen cancels on 25 August, outside the 30-day window, so his label is 0: the model is asked about the next 30 days only. And tenure_days is computed up to the cut-off, not up to today. If you computed tenure up to the cancellation date instead, short tenures would mark exactly the customers who left, and the model would learn the answer from the question.
In a real project you repeat this for many cut-off dates (1 January, 1 February…) and stack the rows, so the model sees many months of history. Every feature in every row must be computed as of that row's own cut-off date.
04. Five learning paradigms
Once the target is defined, the data you have decides the paradigm, the general way the model learns.
- Supervised learning learns from examples that have the correct answer attached. If the answer is a category it is classification: binary (cancel or not) or multi-class (which of 12 queues). If the answer is a number on a scale it is regression (days until delivery, price). A category coded as a number is still a category: queue 7 is not "between" queues 6 and 8.
- Unsupervised learning finds structure without any target: clusters of similar customers, unusual transactions, a compressed representation. Its output has no built-in meaning; a cluster is only a group of similar rows until a person interprets it.
- Semi-supervised learning combines a few labelled examples with many unlabelled ones. A common form is pseudo-labelling: use the labelled rows to guess labels for unlabelled rows that resemble them, then train on both.
- Self-supervised learning creates its own targets from the raw data, for example by hiding a word in a sentence and predicting it, or predicting the next frame of a video. A model pre-trained this way on lots of unlabelled data learns useful representations, and is then fine-tuned on a small labelled set. The pre-training of large language models works like this.
- Reinforcement learning learns by acting in an environment and receiving rewards. It fits when each decision changes what happens next and you can try actions safely, as in games, robotics or some pricing systems. It needs a way to explore, so it is rarely the right first choice when a historical labelled dataset already exists.
Labels are often the scarce resource. The demo below gives a model only 50 labelled images of handwritten digits and 1,207 unlabelled ones. A purely supervised model can only use the 50. LabelSpreading spreads each known label to images that are near it in pixel space; a logistic regression then learns from the resulting pseudo-labels.
import numpy as np
from sklearn.datasets import load_digits
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.semi_supervised import LabelSpreading
X, y = load_digits(return_X_y=True)
X = X / 16.0 # pixel values from 0 to 1
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=0
)
rng = np.random.default_rng(0)
labelled = rng.choice(len(y_train), size=50, replace=False) # only 50 labels
y_partial = np.full_like(y_train, -1) # -1 means "no label"
y_partial[labelled] = y_train[labelled]
print("labelled rows:", len(labelled), "| unlabelled rows:", (y_partial == -1).sum())
supervised = LogisticRegression(max_iter=2000).fit(X_train[labelled], y_train[labelled])
print("supervised, 50 labels only:", round(supervised.score(X_test, y_test), 3))
# Semi-supervised: spread the 50 labels to similar unlabelled images...
spreading = LabelSpreading(kernel="knn", n_neighbors=7).fit(X_train, y_partial)
pseudo = spreading.transduction_ # a label for every training row
unlabelled = y_partial == -1
print("pseudo-labels that are correct:",
round((pseudo[unlabelled] == y_train[unlabelled]).mean(), 3))
# ...then train the same model on all 1,257 rows with their pseudo-labels
pseudo_model = LogisticRegression(max_iter=2000).fit(X_train, pseudo)
print("trained on pseudo-labels:", round(pseudo_model.score(X_test, y_test), 3))labelled rows: 50 | unlabelled rows: 1207
supervised, 50 labels only: 0.776
pseudo-labels that are correct: 0.902
trained on pseudo-labels: 0.9The pseudo-labels are wrong for about 10% of the images, yet training on them lifts test accuracy from 0.776 to 0.900. The unlabelled images taught the model what digits look like, and the 50 labels only had to name the groups. The gain is not guaranteed. In four runs with different random sets of 50 labelled images, it ranged from about 4 to 15 percentage points, and pseudo-labelling can hurt when the labelled examples are unrepresentative or the classes overlap. Always compare against the supervised-only model on the same test set.
05. Check your understanding
06. Apply it
The practice project for this skill starts with a one-page problem framing for a public tabular dataset. Write it now for the breast cancer dataset in scikit-learn (load_breast_cancer), imagining that a clinic uses the model to decide which biopsy results get a second review.
- Answer the six framing questions in one or two sentences each.
- Name the paradigm and task type, and say why the others do not fit.
- List any column you would refuse to use as a feature in a real clinic, and explain what information it would need to exist at prediction time.
07. Review prompt
Without looking back, list the six framing questions in order and explain why the prediction time decides which features are allowed. Then describe one situation that fits each of the five paradigms, and say what pseudo-labelling does and when it can make a model worse.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.