32. Features and Labels in Machine Learning
32.1 Features (X) and Labels (y) in Plain Words
Why. sklearn code writes X and y. If those letters feel scary, stop here and make them boring.
What.
- Features (X) — input columns the model is allowed to look at (items, distance, rain…).
- Label (y) — the answer column you want to guess (was_late, amount, churn…).
Memory trick: X = eXplanatory inputs. y = the why we care about (the target).
How.
import pandas as pd
df = pd.DataFrame({
"items": [2, 5, 3],
"distance_km": [1.2, 4.0, 2.5],
"was_late": [0, 1, 0],
})
X = df[["items", "distance_km"]] # features
y = df["was_late"] # label
print("X columns:", list(X.columns))
print("y name:", y.name)
Ravindra Bagale's Tip
Notebook madhe pehle cell: X = … y = … Explicit. “df iloc magic” ne gungunat kaam karu naka. Clear names. Bilkul visru naka.