QUESTION 10 OF 15

Why use an sklearn pipeline?

Reveal the answer and explore the explanation.

10
Hard

Why use an sklearn pipeline?

Answer
Answer

Chains fitted preprocessing and modeling steps consistently.

Practical example

Cross-validate scaling and a classifier as one estimator.

PythonRelated concept example
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
model = make_pipeline(StandardScaler(), LogisticRegression())
# Fit model on training data only.

A pipeline keeps fitted preprocessing inside cross-validation.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As