← Master Index
Vol. 05 Module 5.1 Lecture

Label

ML Fundamentals

How This Lesson Fits the Module

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 y from 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 typeLabel (y)Example metric (later)
Binary classification0/1 or two classesROC-AUC, F1
Multiclass classificationCategory A/B/CMacro-F1, log loss
RegressionContinuous numberRMSE, MAE
Ranking / otherGrades, 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.

import pandas as pd # Binary churn: did user cancel within 30 days after snapshot? y = df["churned_30d"].astype(int) # Regression: revenue in next quarter y_reg = df["revenue_next_q"] # Multiclass: support ticket priority y_mc = df["priority_class"] # e.g. low / medium / high assert len(X) == len(y) print(y.value_counts(normalize=True)) # check imbalance
Critical Mistake — Label Definition Drift

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.

IssueSymptomEngineering response
Severe imbalance99% negativesStratified splits; precision-recall focus
Label noiseExperts disagreeAudit sample; improve annotation
Delayed labelsRecent rows lack yExclude immature rows from training
Proxy labelsClick instead of purchaseDocument bias; validate with A/B
Engineering Habit — Label Contract

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

  1. Short Answer: What is y in supervised learning? Answer: The target label the model learns to predict.
  2. True/False: Labels are available at production inference time. Answer: False—that would be leakage.
  3. Multiple Choice: Predicting house price is: (a) classification, (b) regression, (c) clustering. Answer: (b).
  4. Short Answer: Why check len(X) == len(y)? Answer: Each feature row must pair with exactly one label.
  5. Short Answer: What is class imbalance? Answer: One class is much rarer than others in y.
  6. True/False: Proxy labels are always equivalent to true business outcomes. Answer: False—they introduce bias.
  7. Multiple Choice: Rows without mature label window should be: (a) forced to y=0, (b) excluded, (c) duplicated. Answer: (b).
  8. Short Answer: Binary vs multiclass label? Answer: Binary has two outcomes; multiclass has three or more categories.
  9. Short Answer: Why document label SQL? Answer: Reproducibility and alignment between teams and environments.
  10. 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 y aligned with X; profile balance and noise early.
  • Immature or proxy labels need explicit handling in the dataset.
  • Next: Training Set—where the model actually learns.
Trainer’s Guide

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.