Skip to content

Pei-Tong/Customer-Purchase-Predict_ML

Repository files navigation

Customer Purchase Prediction

ML-Zoomcamp Mid-Project

Overview

This project is designed to predict the likelihood of a customer making a purchase based on demographic and behavioral features. It incorporates data preprocessing, exploratory data analysis (EDA), model training, and deployment through a web interface using Streamlit.

The model utilizes a Random Forest Classifier to predict purchase probabilities. The project includes local deployment using Docker, with bonus deployment steps for cloud environments.


Features

Input Features:

  • Age
  • Annual Income
  • Discounts Availed
  • Loyalty Program Status
  • Number of Purchases
  • Time Spent on Website

Output:

  • Predicted probability of purchase (a value between 0 and 1).

Project Structure

The project includes the following files:

  • notebook.py:

    • Data preparation and cleaning
    • Exploratory Data Analysis (EDA)
    • Model training and hyperparameter tuning
  • train.py:

    • Training the Random Forest Classifier
    • Saving the trained model using pickle
  • predict.py:

    • Loading the model
    • Function to predict customer purchase probabilities
  • app.py:

    • Streamlit-based web application
  • Dockerfile:

    • Instructions for containerizing the application
  • requirements.txt:

    • List of dependencies for the project
  • Dataset:

    • A CSV file containing the customer dataset (instructions provided to download it if not included).

Prerequisites


Setup and Execution

A. Operation Locally

Step 1: Clone the Repository
git clone https://github.com/Pei-Tong/ml-zoomcamp-midproject.git
cd ml-zoomcamp-midproject
Step 2: Install Dependencies

Create a virtual environment and install dependencies:

python -m venv venv
source venv/bin/activate # For Linux/Mac
venv\Scripts\activate    # For Windows
pip install -r requirements.txt
Step 3: Run the App Locally
streamlit run app.py

B. Using Docker

Step 1: Build the Docker Image
docker build -t customer-purchase-prediction .
Step 2: Run the Docker Container
docker run -p 8501:8501 customer-purchase-prediction

C. Cloud Deployment

The application has been deployed online for easy access. You can use the following link to test the app:

Customer Purchase Prediction App

The online deployment ensures that users can interact with the app without needing to set up the environment locally. All functionalities, including inputting customer data and obtaining purchase probability predictions, are fully operational.


Project Deliverables

  • A Streamlit application for customer purchase prediction.
  • Docker container for easy deployment.
  • Dataset analysis and preprocessing script in notebook.py.
  • Trained model and prediction scripts.

Web Interface

The following is a screenshot of the Customer Purchase Prediction app interface: App Screenshot


Acknowledgements

About

Use random forest to predict customer purchase status

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published