Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploying Machine Learning Models using FastAPI and Docker

This example focuses on the following:

  • Building a machine learning model with Scikit-learn (model train and save)
  • Creating a FastAPI to serve predictions
  • Containerizing the API using Docker

Installation

  • Create a virtual environment
python3 -m venv ~/opt/MLFlow
  • Activate it and install necessary packages using requirements.txt
source ~/opt/MLFlow/bin/activate
pip install -r requirements.txt
  • Build the Docker image by running the following docker build command:
docker build -t house-price-prediction-api .
  • Next run the Docker container:
docker run -d -p 80:80 house-price-prediction-api

Your API should now be running and accessible at http://127.0.0.1:80.

You can use curl or Postman to test the /predict endpoint by sending a POST request. Here’s an example request:

curl -X 'POST' \
  'http://127.0.0.1:80/predict' \
  -H 'Content-Type: application/json' \
  -d '{
  "MedInc": 3.5,
  "AveRooms": 5.0,
  "AveOccup": 2.0
}'

Also, you can run the following command to execute the docker inside

docker exec -it [docker-id] /bin/bash

To find the Docker ID:

docker ps

About

MLOps for house price prediction

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages