C.W.K.
Stream
Lesson 05 of 10 · published

Features, Labels, Examples, Datasets

~30 min · features, labels, tabular-data

Level 0Scout
0 XP0/48 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

A dataset is a contract too

A supervised dataset is not just a table. Each row is an example. Features describe what is known at prediction time. The label is the answer the model is allowed to learn from during training. The hardest part of dataset design is being honest about which columns belong in which role.

Three questions per column

  1. What does this column mean in business terms? If you cannot say it in one sentence, the column is a future bug.
  2. When is this value known? If it only exists after the prediction, it is leakage.
  3. Could it accidentally encode the target? Hash-encoded categorical IDs, post-event statuses, support-call counts, and refund amounts are common offenders.

Schema as a guard

A small column-audit DataFrame is one of the highest-leverage habits in classical ML. It forces you to mark each column as feature, label, identifier, leakage risk, or post-event metadata. Once it exists, every new column has to pick a role to enter the pipeline.

Code

A column-audit table for a churn dataset·python
import pandas as pd

audit = pd.DataFrame([
    {"column": "customer_id", "role": "identifier", "known_at_prediction": True, "use": False},
    {"column": "plan_tier", "role": "feature", "known_at_prediction": True, "use": True},
    {"column": "tickets_last_30d", "role": "feature", "known_at_prediction": True, "use": True},
    {"column": "days_since_signup", "role": "feature", "known_at_prediction": True, "use": True},
    {"column": "cancel_reason_text", "role": "post_event", "known_at_prediction": False, "use": False},
    {"column": "refund_amount", "role": "post_event", "known_at_prediction": False, "use": False},
    {"column": "churned", "role": "label", "known_at_prediction": False, "use": "target"},
])
feature_cols = audit.loc[audit["use"] == True, "column"].tolist()
Use the audit as the only path into the model·python
X = df[feature_cols].copy()
y = df["churned"]
assert "cancel_reason_text" not in X.columns, "leakage column slipped through"

External links

Exercise

Write a column-audit DataFrame for a real (or imagined) churn or fraud dataset. Mark every column as feature, label, identifier, post-event, or leakage. Save it as column_audit.csv and reference it from your training script.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.