Calmcode - scikit learn: pipeline

Pipelines in Scikit-Learn

1 2 3 4 5 6 7 8 9 10

Let's add a preprocessing step by introducing it in a pipeline.

from sklearn.neighbors import KNeighborsRegressor
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_boston
from sklearn.pipeline import Pipeline
import matplotlib.pylab as plt

X, y = load_boston(return_X_y=True)

pipe = Pipeline([
    ("scale", StandardScaler()),
    ("model", KNeighborsRegressor())
pred =, y).predict(X)
plt.scatter(pred, y)

Note that this pipe also has the same .fit(X, y).predict(X) api.