Pipeline

noun

say it: “PYP-lyn” /ˈpaɪpˌlaɪn/

In scikit-learn, an object that joins data-preparing steps and a model into one, so they are fitted and used together, in order.

What is a Pipeline in scikit-learn?

A Pipeline in scikit-learn chains preparing steps and a model into one object: fit() fits each step in order on the training rows, and predict() runs new rows through the same steps. The steps only learn from the rows given to fit(), so cross-validating a pipeline can't leak test rows into the preparation.

from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
model = Pipeline([("scale", StandardScaler()), ("knn", KNeighborsClassifier(n_neighbors=1))])
model.fit([[120, 3], [180, 9]], ["lemon", "orange"])   # grams, sweetness
print(model.predict([[130, 4]]))   # ['lemon']

In a sentence

  • “The pipeline scaled the features and then ran the classifier, all from one fit() call.”
  • “Saving the whole pipeline meant the scaler went to production with the model.”

Level: Journeyman · More Python terms at this level

Updated

In other subjects