Skip to content

duytran-git/customer-bought-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Customer Bought Prediction API

A Dockerized FastAPI machine learning inference service that predicts whether a customer will buy a product based on basic demographic and pricing information.

This project demonstrates an end-to-end ML engineering workflow:

  • data preprocessing
  • model training (offline)
  • model serialization
  • API inference
  • automated testing
  • Docker packaging

Project Overview

This API predicts a binary outcome:

  • 0 → customer is unlikely to buy
  • 1 → customer is likely to buy

It uses a scikit-learn model trained on processed customer data and exposes predictions via a FastAPI REST endpoint.


Project Structure

customer-bought-api/
├─ app/
│  ├─ artifacts/
│  │  ├─ final_model.joblib
│  │  └─ feature_columns.joblib
│  ├─ __init__.py
│  ├─ main.py
│  ├─ preprocessing.py
├─ tests/
│  ├─ test_health.py
│  └─ test_predict.py
├─ client.py
├─ Dockerfile
├─ requirements.txt
├─ .dockerignore
└─ README.md

ML Design

This project uses an old-style ML deployment approach:

  • final_model.joblib → trained model
  • feature_columns.joblib → feature schema
  • preprocessing.py → transforms raw input into model-ready features

⚠️ If preprocessing logic changes, the model must be retrained and artifacts regenerated.


Run with Docker

Build image

docker build -t customer-bought-api .

Run API

docker run -p 8000:8000 customer-bought-api

Endpoints:


Run Tests

docker run --rm customer-bought-api pytest -q

Example Request

curl -X POST http://localhost:8000/predict   -H "Content-Type: application/json"   -d '{"age":40,"income":70000,"country":"USA","price":150}'

Example response:

{
  "prediction": 1,
  "probability_bought_1": 0.73,
  "model": "DecisionTreeClassifier"
}

Tech Stack

  • Python
  • FastAPI
  • scikit-learn
  • pandas / numpy
  • pytest
  • Docker

Author

Duy Tran | Aspiring AI and Machine Learning Engineer

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published