Skip to content

SiddharthUchil/customer_segmentation

Repository files navigation

End-to-end Customer Segmentation Project

Project Structure

  • src: consists of Python scripts
  • config: consists of configuration files
  • data: consists of data
  • processors: consists of all scikit-learn's transformers used to process the new input

Set Up the Project

  1. Clone this branch:
git clone --branch bentoml_demo https://github.com/SiddharthUchil/customer_segmentation.git
  1. Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Pull data
dvc pull

Run the Project

To run all flows, type:

python src/main.py

Serve Machine Learning Models with BentoML

To serve the trained model, run:

bentoml serve src/bentoml_app.py:service --reload

Now you should be able to interact with the API by going to http://127.0.0.1:5000 and clicking the "Try it out" button:

To send requests to the newly started service in Python, run:

python src/predict.py

Details of predict.py:

import requests

prediction = requests.post(
    "http://127.0.0.1:5000/predict",
    headers={"content-type": "application/json"},
    data='{"Income": 58138, "Recency": 58, "Complain": 0,"age": 64,"total_purchases": 25,"enrollment_years": 10,"family_size": 1}',
).text

print(prediction)

Output:

1

Run a Streamlit app

To open a Streamlit app, run:

streamlit run src/streamlit_app.py

then go to http://localhost:8501. You should see a web app like below:

About

An end-to-end project on customer segmentation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published