Skillversitas

MLOps and Model Deployment

Training a model is only half the job. MLOps is the practice of shipping, monitoring, and maintaining models in production so they keep delivering value instead of silently degrading.

Saving and Loading Models

joblib handles scikit-learn models and arbitrary Python objects; other frameworks have their own save APIs:

import joblib

joblib.dump(model, "models/churn_v1.pkl")
loaded = joblib.load("models/churn_v1.pkl")
print(loaded.score(X, y))

Serving as an API

The simplest production pattern is a thin HTTP wrapper around model.predict. FastAPI is a common choice because validation and docs come for free:

from fastapi import FastAPI
from pydantic import BaseModel
import joblib

app = FastAPI()
model = joblib.load("models/churn_v1.pkl")

class Features(BaseModel):
    features: list[float]

@app.post("/predict")
def predict(f: Features):
    proba = model.predict_proba([f.features])[0][1]
    return {"churn_probability": round(float(proba), 4)}

Containerize the service with Docker so training and serving run in the same environment:

docker build -t churn-api:1 .
docker run -p 8000:8000 churn-api:1

The Model Lifecycle

  • Registry: store versioned artifacts (model plus feature definitions plus metrics) so a rollback is one command.
  • Promotion: run staging and shadow traffic before production to compare outputs side by side.
  • Monitoring: log prediction distributions and drift metrics (PSI, KL divergence) on features and labels.
  • Retraining: schedule retraining, compare the challenger against the champion, and redeploy only when it wins.

Summary

Production ML means packaging a trained model into a versioned, monitored service. Save artifacts with joblib, serve predictions through a small FastAPI endpoint in a Docker image, and operate the full lifecycle: registry, promotion, drift monitoring, and scheduled retraining.