Features describe inputs; the label (target, y) is what supervised learning tries to predict. A vague or misaligned label wastes every downstream split, metric, and deployment hour.
AI engineers co-design labels with product and analytics: precise definition, observation window, and class balance—not just “pick a column.”
Learning Objectives
By the end of this lesson, students should be able to:
- Define labels in supervised learning and separate them from features.
- Distinguish classification labels from regression targets.
- Extract
yfrom pandas DataFrames for sklearn APIs. - Evaluate label quality: noise, imbalance, and definitional drift.
- Map business questions to concrete label windows and thresholds.
- Document label rules to prevent train/serve and temporal leakage.
What a Label Is
The label is the ground truth outcome for each row. During training the algorithm adjusts parameters to minimize error between predictions and y. At inference time y is unknown—that is the whole point of the model.
| Problem type | Label (y) | Example metric (later) |
|---|---|---|
| Binary classification | 0/1 or two classes | ROC-AUC, F1 |
| Multiclass classification | Category A/B/C | Macro-F1, log loss |
| Regression | Continuous number | RMSE, MAE |
| Ranking / other | Grades, scores (advanced) | NDCG, custom |
Extracting y in pandas
Keep y as a 1D series aligned row-for-row with X. Use consistent dtypes—strings for multiclass, numeric for regression.
Training on “churn within 30 days” but evaluating live on “90-day churn” is not the same problem. Version label SQL and tie dashboards to the exact definition used in y.
Label Quality and Imbalance
Rare positives (fraud, churn, defects) dominate metric choice and threshold tuning. Noisy labels from weak heuristics cap model performance—garbage in, ceiling out.
| Issue | Symptom | Engineering response |
|---|---|---|
| Severe imbalance | 99% negatives | Stratified splits; precision-recall focus |
| Label noise | Experts disagree | Audit sample; improve annotation |
| Delayed labels | Recent rows lack y | Exclude immature rows from training |
| Proxy labels | Click instead of purchase | Document bias; validate with A/B |
Write: “Label = 1 if subscription_status becomes ‘canceled’ within 30 calendar days after snapshot_date, else 0. Rows with <30 days of follow-up are excluded.” Attach SQL and owner sign-off.
Knowledge Check
- Short Answer: What is
yin supervised learning? Answer: The target label the model learns to predict. - True/False: Labels are available at production inference time. Answer: False—that would be leakage.
- Multiple Choice: Predicting house price is: (a) classification, (b) regression, (c) clustering. Answer: (b).
- Short Answer: Why check
len(X) == len(y)? Answer: Each feature row must pair with exactly one label. - Short Answer: What is class imbalance? Answer: One class is much rarer than others in
y. - True/False: Proxy labels are always equivalent to true business outcomes. Answer: False—they introduce bias.
- Multiple Choice: Rows without mature label window should be: (a) forced to y=0, (b) excluded, (c) duplicated. Answer: (b).
- Short Answer: Binary vs multiclass label? Answer: Binary has two outcomes; multiclass has three or more categories.
- Short Answer: Why document label SQL? Answer: Reproducibility and alignment between teams and environments.
- Multiple Choice: For fraud detection with 0.1% positives, first split concern: (a) stratify, (b) shuffle time, (c) drop features. Answer: (a).
Key Takeaways
- The label defines the business problem—precision matters more than model choice.
- Keep
yaligned withX; profile balance and noise early. - Immature or proxy labels need explicit handling in the dataset.
- Next: Training Set—where the model actually learns.
Hands-on idea: Teams rewrite a vague stakeholder ask (“predict unhappy customers”) into a measurable label spec with window, positives definition, and exclusion rules.
Discussion prompt: Using “clicked unsubscribe link” as churn label—what false positives and false negatives do you expect?
Recap: Labels are the targets you want to predict; define them with clear rules and time windows. Continue with Training Set.