Skip to main content
Albero Academy

Pipelines

Chain preprocessing and a model into one leakage-safe object.

Preprocessing9 min

A Pipeline chains preprocessing steps and a final model into a single estimator. It's not just tidy — it's the correct way to prevent data leakage, because every step is fit on training data only, automatically.

Building a pipeline

steps in sequence
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
pipe = make_pipeline(
StandardScaler(),
LogisticRegression(),
)
pipe.fit(X_train, y_train) # scaler.fit_transform then model.fit — on train
pipe.predict(X_test) # scaler.transform then model.predict — on test

Why pipelines matter

Key takeaways

  1. 01A Pipeline chains preprocessing steps and a model into one estimator.
  2. 02Every step is fit on training data only — leakage-safe by construction.
  3. 03It behaves like any estimator: fit/predict/score.
  4. 04Pipelines make cross-validation and grid search correct (preprocessing re-fit per fold).

Finished this chapter?

Mark it complete to track your progress through Scikit-learn.