Block 69: Wrapping ML Models as APIs
Serve a pre-trained ML model as an API endpoint.
Concepts
- Loading a saved model (joblib or pickle)
- Accepting input data via Pydantic model
- Running prediction and returning result
- Input validation for ML features
Code Examples
See exercise below.
Exercise
Train a simple Iris classifier with scikit-learn, save it, and serve predictions via a FastAPI endpoint that accepts sepal/petal measurements. Test it with valid and invalid inputs.
Homework
What additional concerns arise when deploying an ML model as an API vs a static data API?