Features & Labels
X and y — the inputs and outputs of every supervised ML model
Free tier: read the explanation here. Upgrade to Pro for Drills, Speed challenges & Mastery badges.
UpgradeKnowledge Debt detected
You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.
Explanation
Features (X) — the input variables the model uses to make predictions. Also called: independent variables, predictors, attributes, inputs.
Labels (y) — the output variable the model predicts. Also called: target, dependent variable, response.
import pandas as pd
from sklearn.model_selection import train_test_split
df = pd.read_csv('titanic.csv')
# Features: everything except the target
X = df[['pclass', 'age', 'fare', 'sex_encoded']]
# Label: what we want to predict
y = df['survived']
X_train, X_test, y_train, y_test = train_test_split(X, y)Feature engineering — creating new features from existing ones: ``python df['family_size'] = df['siblings'] + df['parents'] + 1 df['is_alone'] = (df['family_size'] == 1).astype(int)
Feature importance: Most algorithms can tell you which features most influenced predictions — critical for interpretability.
Curse of dimensionality: Too many features (especially irrelevant ones) can hurt model performance. Feature selection is an important skill.
Examples
Preparing X and y from a DataFrame
feature_importances_ shows which features the model relied on most
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
df = pd.DataFrame({'age':[25,35,45,28,52],'salary':[40,70,90,45,95],'bought':[0,1,1,0,1]})
X = df[['age', 'salary']] # features
y = df['bought'] # label
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestClassifier()
model.fit(X_train, y_train)
# Feature importances
for feat, imp in zip(X.columns, model.feature_importances_):
print(f"{feat}: {imp:.3f}")How well did you understand this?
Next in Machine Learning Basics
scikit-learn Pipeline