1
$\begingroup$

Following ML best practices, I use Scikit Pipelines to make sure my data preprocessing is the same at each model development iteration.

Also as a best practice, once I have completed model development I retrain the best model with the chosen hyperparameters on the entire dataset.

Now, in order to prepare for a deployment to production, I am trying to understand if I should export the model chosen itself, or the entire Pipeline object? I would want to apply the same exact preprocessing steps in production, correct?

$\endgroup$
1
$\begingroup$

You have to export the model which includes the list of transformers defined by the pipeline and the final estimator.

To give a simple example:

from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
from sklearn.pipeline import Pipeline

X, y = load_boston(return_X_y=True)
pipe = Pipeline(steps=[('scaler', StandardScaler()), ('linreg', LinearRegression())])
pipe.fit(X, y)

Now you can save your model for example via pickle for use in production:

import pickle
s = pickle.dumps(pipe)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.