Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI + Scikit-Learn Model Deployment

Machine Learning API

A REST API built with FastAPI to serve a classification model trained with scikit-learn.

This project showcases a complete end-to-end model deployment pipeline, including:

  • Model training
  • Model serialization using joblib
  • API exposure via FastAPI
  • Containerization with Docker

Project Architecture

tp6_api_diegodm/
│
├── app/
│   ├── main.py        # FastAPI app and endpoints
│   ├── model.py       # Model loading and prediction logic
│   └── schemas.py     # Data validation using Pydantic
│
├── models/
│   ├── final_meta_classifier.joblib
│   └── ...
│
├── Dockerfile         # Deployment image
├── requirements.txt   # Python dependencies
└── README.md

Requirements

  • Python 3.10+
  • pip
  • Docker (optional, for deployment)

Installation

pip install -r requirements.txt

Run the API Locally

uvicorn app.main:app --reload --port 8000

The API will be available at:

http://127.0.0.1:8000

Interactive documentation (Swagger UI):

http://127.0.0.1:8000/docs

FastAPI automatically generates a Swagger UI interface to test endpoints in real time.


Available Endpoints

Health Check

GET /health

Checks the service status and whether the model is loaded.

Example response:

{
  "status": "healthy",
  "model_loaded": true,
  "model_version": "1.0"
}

Prediction

POST /predict

Request:

{
  "feature_1": 1.0,
  "feature_2": 2.0,
  "feature_3": 3.0
}

Response:

{
  "label": 1,
  "probability": 0.999,
  "model_version": "1.0"
}

Docker

Build the Image

docker build -t <username>/tp6-api:1.0 .

Run the Container

docker run --rm -p 8000:8000 <username>/tp6-api:1.0

Verify the Service

curl http://127.0.0.1:8000/health

Publish to Docker Hub

Login:

docker login

Push the image:

docker push <username>/tp6-api:1.0

Technical Notes

  • The model is loaded once at application startup to minimize latency.
  • Input validation is handled using Pydantic (app/schemas.py).
  • If the model features change, you must update:
app/schemas.py  
app/main.py  

Tech Stack

  • FastAPI
  • Scikit-Learn
  • Pydantic
  • Uvicorn
  • Docker
  • Joblib

About

End-to-end machine learning deployment pipeline using FastAPI, Scikit-Learn, and Docker, including model serving, validation, and containerization.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages