End-to-end modeling
Combine preprocessing and prediction into one fit/predict object.
Scikit-Learn · Function
Constructs a scikit-learn Pipeline from estimators supplied in order. It automatically generates lowercase step names from estimator types.
Pass transformers and a final estimator in execution order. The function builds a Pipeline, automatically deriving each step name by lowercasing its estimator type; the resulting pipeline can be fitted and used for prediction as a single estimator.
sklearn.pipeline.make_pipeline(*steps, memory=None, transform_input=None, verbose=False)| Name | Type | Description |
|---|---|---|
steps | estimators | Ordered estimator objects to chain into the pipeline. |
memory | str or object, default=None | Cache location or a joblib.Memory-compatible object; default=None. |
transform_input | list of str, default=None | Names of fit inputs other than X to transform through relevant preceding steps; default=None. |
verbose | bool, default=False | Whether to print elapsed fitting time for each step; default=False. |
A scikit-learn Pipeline object.
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
X, y = load_iris(return_X_y=True)
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=200))
model.fit(X, y)
print(model.predict(X[:3]))Standardizes the features and then fits a logistic-regression classifier as one estimator.
Combine preprocessing and prediction into one fit/predict object.
Reuse the same transformation sequence during validation and inference.
Avoid repeating expensive transformer fitting across compatible runs.
make_pipeline accepts a variable number of estimators and returns a Pipeline containing them in the supplied order. It automatically names each step from the lowercase estimator type, so explicit step names are not provided.
Follow-up: When are explicit names preferable? Use Pipeline when stable, custom names are needed for parameter searches or inspection.
The steps are chained sequentially: transformers process the data before the final estimator receives it. The returned Pipeline exposes the composite estimator interface, including fitting and prediction when its last step supports those operations.
Follow-up: How would you inspect a particular step? Access the pipeline's named_steps or steps attributes.
memory accepts a path or an object implementing the joblib.Memory interface. It caches fitted transformers, while caching is disabled by default and the final step is excluded from caching.
Follow-up: What additional behavior should be considered when caching? Transformer instances are cloned before fitting, so inspect the fitted pipeline steps.
Pipelinemake_unionFeatureUnion