I am having pretrained Sklearn model and pre-trained Standard scalar object saved as pickle . And now I want to create Sklearn pipeline using both of it.

I need sklearn pipeline to convert it into ONNX format.

I couldnt do it as pipeline takes standard scalar class and then we need fit pipeline using data but in my case models and scalar both are already fitted.


1 Answer 1


This works the way you would want out of the box.

pipeline takes standard scaler class

No, pipelines get initialized with estimator instances, not the classes. (This is why you need the parentheses in the steps, e.g. StandardScaler().)

That is, the following works:

from sklearn.datasets import load_breast_cancer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline

X, y = load_breast_cancer(return_X_y=True)

scaler = StandardScaler()
lr = LogisticRegression()

X_sc = scaler.fit_transform(X)
lr.fit(X_sc, y)

pipe = Pipeline(steps=[('scale', scaler),
                       ('lr', lr)])

# Predicting would fail if the pipeline had unfitted estimators:
  • 1
    $\begingroup$ Ha that means once running pipe = Pipeline(steps=[('scale', scaler),('lr', lr)]) I dont need to fit it back as both of them are already fitted $\endgroup$ Commented Jul 20, 2020 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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