From a fitted model to a live system.
Understand saved pipelines, input contracts, monitoring, drift, and safe fallback behavior.
Start with the meaning.
A fitted model in a notebook is only one piece of a service. A live system receives new data, validates its shape, applies the same preprocessing, makes a prediction, and communicates or acts on the result. If the training pipeline used a median imputer and category encoder, the live system must use those exact fitted objects. Rebuilding them from each request changes the feature meaning and invalidates the model's learned relationships.
An input contract states required fields, types, units, allowed missing values, and the prediction moment. A model trained on annual income cannot silently accept monthly income under the same column name. A new category may need a defined unknown-category behavior. Rejecting malformed input clearly can be safer than forcing a prediction from an invented value. Output contracts describe what the score means and what action, if any, follows it.
How the idea works.
Saving a fitted pipeline allows a later process to load its learned state. Python serialization formats such as joblib or pickle can execute code when loading untrusted files, so model artifacts must come from a trusted source and be versioned with their software environment. A saved artifact should be linked to its training data definition, preprocessing, model settings, evaluation report, and code version. Without that context, a future maintainer cannot tell what a number means.
Drift is change between the setting represented by training data and the setting the live system now sees. Input drift means feature distributions change. Concept drift means the relationship between features and target changes. Label delay may mean the true outcome is not known for weeks, so immediate monitoring can only track inputs and predictions, not accuracy. When outcomes arrive, evaluate errors by time and relevant subgroups.
Monitoring should distinguish data-quality failures, model behavior, and business outcomes. A sudden rise in missing values may indicate a broken upstream feed. A shift in prediction scores may reflect changing customers or an encoding problem. A stable overall score can hide a subgroup regression. A fallback—manual review, a simple baseline, or a temporary stop—should be designed before failure, especially when predictions trigger consequential actions.
Follow the code.
def validate_row(row):
area = row.get("area")
if not isinstance(area, (int, float)) or area <= 0:
raise ValueError("area must be a positive number")
return [[float(area)]]
incoming = {"area": 72}
features = validate_row(incoming)
print(features)
# A trusted, fitted pipeline would receive features for prediction.The function receives a dictionary representing one incoming case. get returns the area value or None if missing. isinstance checks whether it is a numeric Python type, and the comparison rejects zero or negative area. A valid value is converted to float and wrapped in two levels of brackets: one row containing one feature, the shape expected by a scikit-learn predictor. The example prints [[72.0]]. It deliberately stops before loading an artifact because a real artifact must be trusted and tied to a defined feature schema.
The validation is specific to this toy area feature. Python booleans are subclasses of int, so a stricter contract would explicitly reject True and False; a production schema would also document units and reject non-finite values such as NaN. The lesson is that input checking must be designed from the real data contract, not inferred from whether predict happens to accept a value.
What the result does not say.
Retraining is a controlled change to a decision system. It needs comparable evaluation, artifact versioning, and a way to roll back if behavior worsens. More recent data is not automatically better when labels are delayed or a temporary event dominates it.
Human feedback can improve a model only if it is collected and interpreted carefully. Corrections may come mostly from cases people noticed, not a representative sample. Monitoring is therefore a continuing evidence process rather than one dashboard number.
One clear idea.
The live product is the whole validated pipeline, monitored over time—not a lone predict call.
The ML cookbook
Complete, explained Python workflows sit alongside this reading course.