Labels, features, splits: the supervised skeleton
Supervised learning, stripped of ceremony: you have rows, each with features (X — what you knew at prediction time) and a label (y — what happened). A model learns the mapping from X to y on some rows so it can predict y for rows it hasn't seen.
Run the editor. That's the entire data shape: X is a list of
feature rows, y the matching labels, and a split separates the
rows you learn from and the rows you judge on. In sklearn the same
skeleton is:
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y)
random_state makes the split reproducible; stratify=y keeps the
label's base rate equal on both sides — which matters exactly when
the base rate is small (chapter 38).
Choosing the label is the real design work
The label defines the product. "Churned" sounds obvious until you must write it as a rule: no login for 30 days? subscription cancelled? Both are defensible; they build different models. Write the label rule down as code (a chapter-36 query), date-stamp it, and treat changes to it like schema changes — everything downstream shifts when it moves.
And the iron rule from chapter 38 travels with it: every feature must be computable before the label window opens.
Split by time when time exists
The editor split by month, not randomly. For anything predictive — churn, fraud, demand — that's the honest split: train on the past, test on the later period, because that's the direction production faces. Random splits are fine for order-free data (is this image a cat), and actively misleading for temporal data.
Where AI specifically gets this wrong
- Random splits on temporal data. sklearn's default is random; Cursor reaches for it reflexively. You have to ask for the time split.
- Features assembled after the split decision. Compute features with the cutoff rule first; split second; never let test rows influence feature statistics (chapter 38's leakage list).
- Undefined labels. "Predict bad customers" with no written rule for bad produces a model nobody can evaluate. The label definition is a contract — put it next to the code.