Why deployment matters as much as accuracy
A model that only runs inside a notebook helps nobody else. Turning it into an API lets a website, a mobile app or another service send data and get a prediction back in milliseconds.
It is also one of the strongest things a learner can show. A portfolio project with a live endpoint proves you can take a model from experiment to something people can actually use.
Deploying a model, step by step
The same pattern works for a scikit-learn classifier, a gradient-boosting model or a small deep learning model.
Train and save the model
Train in a notebook or script, then save the fitted model and its preprocessing (for example a scikit-learn Pipeline) with joblib or pickle.
Write a prediction function
Load the saved model once at start-up and write a function that takes clean input and returns a prediction and, where useful, a probability.
Wrap it in FastAPI
Create a POST /predict endpoint. Define the expected input with a Pydantic model so wrong or missing fields are rejected with a clear error.
Test locally
Run the service with uvicorn, open the automatic /docs page and send sample requests, including bad ones, to check the responses.
Containerise with Docker
Write a Dockerfile that installs pinned library versions and starts the server, so it runs the same everywhere.
Host and monitor
Deploy the container to a cloud service, add basic logging of requests and response times, and watch for inputs that look different from the training data.
Choices you will make along the way
There is no single right stack. These are the common options.
FastAPI or Flask
FastAPI gives input validation and interactive docs out of the box and is popular for ML services. Flask is simpler and very widely used.
Real-time or batch
An API answers one request at a time. If predictions are needed for millions of rows once a day, a scheduled batch job is often simpler.
Where to host
Container services on AWS, Azure or Google Cloud suit production. Free tiers on platforms such as Render or Hugging Face Spaces suit portfolio demos.
Model versioning
Keep each model file with a version number and record which version served each prediction, so you can roll back if a new one performs worse.
Mistakes that break deployed models
Most production problems come from these:
- Saving the model without its preprocessing, so the API receives raw data the model never saw during training.
- Loading the model inside the request handler, which makes every prediction slow.
- Not pinning library versions, so a model saved with one scikit-learn version fails to load with another.
- Accepting any input without validation, which leads to confusing errors or silently wrong predictions.
- Never checking performance after launch, while real-world data slowly drifts away from the training data.
Quick answers about deploying ML models
Short answers to the questions AI learners search for most.
What is model deployment in machine learning?
It is making a trained model available for real use, usually by wrapping it in a service such as a REST API so other applications can send data and receive predictions.
Is FastAPI better than Flask for ML models?
Both work well. FastAPI is often preferred for new ML services because it validates input automatically and generates interactive API documentation, while Flask is simpler and has a very large ecosystem.
Do I need Docker to deploy a model?
Not strictly, but Docker makes deployment reliable by packaging the code, model and exact library versions together, so the service behaves the same on your laptop and in the cloud.
What is MLOps?
MLOps is the set of practices for running models reliably in production: versioning, automated testing and deployment, monitoring and retraining. Deploying a model as an API is the first step into it.
Can I deploy a model for free?
Yes, for learning and portfolio projects. Several platforms offer free tiers that can host a small API or demo app, though they are not meant for heavy production traffic.
Go further with AI engineering
See where deployment sits in the syllabus, or read the guides that build on it.
Ship one model this week
Take a model you have already trained, wrap it in a FastAPI endpoint, put it in Docker and host the free demo. A working link on your resume says more than any accuracy score in a notebook.

