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 productionModels 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.
