Machine Learning
Pipelines
The easiest way to avoid leakage and production bugs.
Why pipelines?
- Same transforms in training and inference.
- Less leakage (fit transforms only on training folds).
- One object to save + deploy.
Minimal pipeline
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
pipe = Pipeline([
("impute", SimpleImputer(strategy="median")),
("scale", StandardScaler()),
("model", LogisticRegression(max_iter=200))
])