Back to questions
JuniorTheoryCommon
What happens on the last line of this program?
import pickle
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
X, y = load_breast_cancer(return_X_y=True)
pipe = Pipeline([("scaler", StandardScaler()), ("model", LogisticRegression())])
pipe.fit(X, y)
model = pickle.loads(pickle.dumps(pipe.named_steps["model"]))
y_pred = model.predict(X)It returns labels with no error, but the model gets unscaled features and most labels are wrong
- Expecting the same labels as the pipeline: the scaling means live in the
scalerstep, so the bare model gets raw features and here puts every row into class0. - Expecting an exception: the model step is fitted and pickles fine, so nothing warns you, and only the quality on held-out data shows the mistake.
- Which object would you save so that a service can call
predicton raw feature rows? - How would you notice this mistake after deployment if no exception is ever raised?