Skip to content
LearnPY
scikit-learnfunction reference

Pipeline

Chain preprocessing and a model into one estimator.

Signature

Pipeline(steps)

What it does

A Pipeline applies each step in order, ending with a final estimator. Fitting the pipeline fits every transformer and the model on the same training rows, which keeps preprocessing inside cross-validation and prevents leakage.

Parameters

stepslist of (name, estimator) tuples
Ordered transforms followed by a final estimator.

Returns

Pipeline

Example

pythonPipeline example
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression

model = Pipeline([
    ("scale", StandardScaler()),
    ("regress", LinearRegression()),
])
model.fit(X_train, y_train)

Watch out for

  • Intermediate steps must implement fit and transform; only the final step needs predict.
  • Step names must be unique and cannot contain a double underscore.