Deploy a Machine Learning Model to Production
Deploying a Model (API, MLOps Basics) is an advanced-level course of 5 lessons (about 4 h 3 min), with 15 exercises and 15 quiz questions. Prerequisites: Model Evaluation and Validation, APIs with FastAPI. The course needs a full project environment, planned for a later phase of the platform.
- Data science
- Advanced
- 5 lessons
- 4 h 3 min
- 15 exercises
- Full project environment (phase 2)
The course in brief
This course takes you from notebook to production on a running example of churn prediction. You will save a model reliably, expose it in a validated FastAPI API, containerize it with Docker, automate tests and promotion, then monitor its behavior and data drift.
What you will be able to do
- Serialize a model pipeline and document the artifact (version, features, metrics, fingerprint)
- Expose a model in a FastAPI API with Pydantic validation, a health endpoint and tests
- Containerize the service with a reproducible and secure Dockerfile
- Set up model tests, a quality gate and continuous integration
- Track experiments and manage model versions in an MLflow registry
- Monitor a model in production: latency, errors, drift (PSI) and retraining strategy
Syllabus: 5 lessons
- Combine preprocessing and model into a single Pipeline
- Save and reload a model with joblib while knowing the risks
- Document an artifact: version, features, metrics, fingerprint and dependencies
- 02
Serving a model with a FastAPI API
- Expose a model through a REST /predict endpoint with FastAPI
- Validate inputs and describe outputs with Pydantic
- Load the model once at startup and handle errors
- 03
Containerizing the service with Docker
- Write a Dockerfile for a model API
- Build, run and inspect a container
- Apply best practices: lightweight image, caching, non-root user, configuration through environment variables
DockerImage and containerConfiguration through the environment
- 04
Tests, continuous integration and model registry
- Write tests for the code, the API and the model's quality
- Automate tests and image building with continuous integration
- Track experiments and promote a model with MLflow
Model testsContinuous integration and deploymentModel registryExperiment tracking
- 05
Monitoring a model in production: logs, drift and retraining
- Log predictions and track operational metrics (latency, errors)
- Detect data drift with PSI and other tests
- Define an alerting and retraining strategy
Final project
Put a churn model into production end to end
Starting from a customer dataset (generated or public), deliver a production-ready churn prediction service: versioned model, documented and tested API, Docker image, CI and a monitoring setup with a drift report over a simulated period.
Deliverables
- A reproducible training script that records the model, its metrics and its card (MLflow or JSON)
- A FastAPI API with /health, /predict and /predict_batch, Pydantic schemas and the model version in responses
- A Dockerfile and a .dockerignore producing a reproducible image that runs without root
- A pytest suite (unit, API and model behavior tests) and a CI workflow that runs it and builds the image
- A monitoring module: structured logs, PSI computation per variable over a simulated period with drift, and a note describing the alerts and the retraining strategy
Assessment criteria
- The service starts with one command and responds correctly to valid and invalid inputs
- Reproducibility: pinned versions, fixed seeds, traceable artifact (version, fingerprint)
- Relevance and automation of tests, explicit quality gate
- Monitoring covering service, data and model, with justified thresholds
- Security and good practices: no secret in the image, input validation, minimized personal data
Frequently asked questions
What are the prerequisites for this model deployment course?
Knowing how to train and evaluate a model with scikit-learn (DS4 course) and the basics of web development in Python and APIs (PW1 course). No prior Docker experience is needed.
Why FastAPI to serve a model?
FastAPI automatically validates input data thanks to Pydantic, generates interactive documentation and offers good performance. It is today one of the most common choices for exposing a model in Python.
What is data drift?
It is the change in the distribution of the data received by the model compared with the training data. It can degrade predictions; it is measured for example with PSI and monitored continuously.
Do I need to know Kubernetes to deploy a model?
No. A Docker image can be deployed on managed container services. Kubernetes becomes useful for large infrastructures, but the principles in the course remain the same.
This course, told for your job
Say what you want to be able to do: “Deploying a Model (API, MLOps Basics)” takes its place in your path, with examples from your field. The concepts stay those of the course.