Machine Learning · Chapter 39 of 40

Deploying an ML Model

DEPLOYMENT makes your model available to real users — usually as a REST API endpoint that takes input and returns predictions.

Common stacks: FastAPI + Docker, cloud services (AWS SageMaker, GCP Vertex AI), or ONNX for edge devices.

Example 1 (python)
# Minimal FastAPI endpoint
from fastapi import FastAPI
import joblib
app = FastAPI()
model = joblib.load('model.pkl')

@app.post('/predict')
def predict(data: dict):
    return {'y': int(model.predict([data['x']])[0])}

One-file inference API.

Example 2 (python)
# Monitor accuracy & data drift in production

Models decay — watch the metrics.

Key points

  • Serve via REST API (FastAPI/Flask).
  • Containerise with Docker for reproducibility.
  • Monitor performance and drift.
  • Retrain on fresh data periodically.
💡 Note: Real-world ML systems fail more often from stale data or bad monitoring than from bad models. Invest in observability.

📝 Quick Quiz

1. A common Python web framework for serving models is:

2. Docker helps with:

3. In production you should monitor: