Ship One Fitted Pipeline

The model begins before the estimator

Wrap preprocessing and the estimator in one Pipeline. During fit, each transformation learns only from the training partition before passing output onward. During predict, stored transformations run without re-fitting. This design prevents leakage and training-serving skew by construction.

from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression

full = Pipeline([('preprocess', prep),
                 ('model', LogisticRegression(max_iter=1000))])
full.fit(X_train, y_train)
pred = full.predict(X_test)

Cross-validation understands pipelines: each fold fits preprocessing only on that fold's training portion. Hyperparameter names use step prefixes such as model__C or preprocess__num__impute__strategy, allowing safe joint tuning.

Warning: Python serialization formats such as pickle can execute code when loaded. Load only artifacts from trusted, integrity-checked sources and pin compatible library versions.
Goal: The existing ml-model-evaluation lab requires a real pipeline so scaling never learns from the held-out data.