Machine Learning
Data & Splits
Train/validation/test the right way and avoid leakage.
Train / Validation / Test
- Train: fit model parameters.
- Validation: tune hyperparameters / select features.
- Test: final unbiased evaluation (use once at the end).
Leakage Checklist
- Preprocessing fitted on full dataset (scale/encode before splitting).
- Using future information to predict the past (time series).
- Target-derived features (anything computed using
y).
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 )