Skip to content

13-Prabhat/E-commerce-Customer-Behavior-Analysis-Segmentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

28 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“Š E-commerce Customer Behavior Analysis & Segmentation

Python License Status Contributions

๐ŸŽฏ Project Overview

This project explores how customers interact with an online store by analyzing their purchase behavior and transaction patterns over time. It transforms raw e-commerce data into actionable business insights through data cleaning, exploratory analysis, RFM (Recency, Frequency, Monetary) segmentation, and machine learning-based clustering.

The goal is to help e-commerce businesses understand their customers better, identify valuable segments, and make data-driven decisions to improve marketing strategies, boost retention, and maximize revenue.


๐Ÿš€ Key Objectives

  • ๐Ÿ“ˆ Understand Customer Patterns: Analyze buying behavior, order frequency, and spending habits
  • ๐ŸŽฏ Segment Customers: Group customers into meaningful segments using RFM analysis and clustering
  • ๐Ÿ’ก Generate Insights: Identify high-value customers, at-risk customers, and new customer opportunities
  • ๐Ÿ“Š Actionable Recommendations: Provide marketing and retention strategies for each customer segment
  • ๐Ÿ”ฎ Predictive Analytics: Build models to predict customer lifetime value and churn risk

๐Ÿ› ๏ธ Tech Stack

Language & Environment:

  • Python 3.8+
  • Jupyter Notebook / JupyterLab

Core Libraries:

  • Data Manipulation: pandas, numpy
  • Visualization: matplotlib, seaborn, plotly
  • Machine Learning: scikit-learn
  • Statistical Analysis: scipy

๐Ÿ“ Project Structure

E-commerce-Customer-Behavior-Analysis-Segmentation/
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ raw/                    # Original dataset files
โ”‚   โ””โ”€โ”€ processed/              # Cleaned and feature-engineered data
โ”‚
โ”œโ”€โ”€ notebooks/
โ”‚   โ”œโ”€โ”€ 01_data_loading_cleaning.ipynb
โ”‚   โ”œโ”€โ”€ 02_eda_customer_behavior.ipynb
โ”‚   โ”œโ”€โ”€ 03_rfm_feature_engineering.ipynb
โ”‚   โ”œโ”€โ”€ 04_customer_segmentation.ipynb
โ”‚   โ””โ”€โ”€ 05_insights_recommendations.ipynb
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ data_processing.py      # Data cleaning utilities
โ”‚   โ”œโ”€โ”€ rfm_calculator.py       # RFM metrics calculation
โ”‚   โ””โ”€โ”€ visualization.py        # Custom plotting functions
โ”‚
โ”œโ”€โ”€ reports/
โ”‚   โ”œโ”€โ”€ figures/                # Generated plots and charts
โ”‚   โ””โ”€โ”€ summary.md              # Final analysis summary
โ”‚
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”œโ”€โ”€ LICENSE                     # MIT License
โ””โ”€โ”€ README.md                   # This file

๐Ÿ“Š Workflow & Methodology

1๏ธโƒฃ Data Collection & Cleaning

  • Load raw e-commerce transaction data
  • Handle missing values, duplicates, and data type conversions
  • Validate data integrity and consistency

2๏ธโƒฃ Exploratory Data Analysis (EDA)

  • Analyze customer demographics and purchase patterns
  • Visualize distributions of orders, revenue, and products
  • Identify trends and anomalies in the data

3๏ธโƒฃ Feature Engineering

  • Create customer-level aggregated metrics
  • Calculate RFM scores:
    • Recency: Days since last purchase
    • Frequency: Total number of orders
    • Monetary: Total amount spent

4๏ธโƒฃ Customer Segmentation

  • Apply K-Means clustering on RFM features
  • Identify optimal number of clusters using Elbow Method and Silhouette Score
  • Label segments with business-friendly names

5๏ธโƒฃ Insights & Recommendations

  • Analyze characteristics of each segment
  • Provide targeted marketing strategies
  • Calculate segment revenue contribution

๐ŸŽฏ Expected Customer Segments

Segment Description Marketing Strategy
๐Ÿ† Champions High RFM scores - best customers VIP rewards, early access, personalized offers
๐Ÿ’Ž Loyal Customers High frequency, regular purchases Loyalty programs, referral incentives
๐ŸŒฑ Potential Loyalists Recent buyers with potential Engagement campaigns, product recommendations
โš ๏ธ At Risk Previously active, now declining Win-back campaigns, special discounts
๐Ÿ†• New Customers Recent first-time buyers Onboarding emails, welcome offers
๐Ÿ’ค Hibernating Low recency and frequency Re-engagement campaigns, surveys

๐Ÿ“ˆ Key Results

๐Ÿ”„ In Progress - Results will be updated as the project progresses through each phase.

Preliminary Findings:

  • Total customers analyzed: TBD
  • Number of segments identified: TBD
  • Revenue contribution by segment: TBD
  • Retention rate insights: TBD

๐Ÿš€ How to Run This Project

Prerequisites

# Python 3.8 or higher
python --version

# Install pip if not already installed
pip --version

Installation

  1. Clone the repository
git clone https://github.com/13-Prabhat/E-commerce-Customer-Behavior-Analysis-Segmentation.git
cd E-commerce-Customer-Behavior-Analysis-Segmentation
  1. Create a virtual environment (optional but recommended)
python -m venv venv

# On Windows
venv\Scripts\activate

# On macOS/Linux
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Launch Jupyter Notebook
jupyter notebook
  1. Run notebooks in sequence
  • Start with 01_data_loading_cleaning.ipynb
  • Follow the numbered order for best results

๐Ÿ“Š Dataset

This project uses the Online Retail Dataset containing transaction data from a UK-based online retailer.

Source: UCI Machine Learning Repository - Online Retail Dataset

Features:

  • InvoiceNo: Transaction ID
  • StockCode: Product code
  • Description: Product description
  • Quantity: Number of items
  • InvoiceDate: Transaction date and time
  • UnitPrice: Price per unit
  • CustomerID: Unique customer identifier
  • Country: Customer location

๐Ÿค Contributing

Contributions are welcome! If you'd like to improve this project:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ‘ค Author

Prabhat


๐ŸŽ“ Learning Outcomes

This project demonstrates:

  • โœ… Data cleaning and preprocessing techniques
  • โœ… Exploratory data analysis and visualization
  • โœ… Feature engineering for customer analytics
  • โœ… Unsupervised machine learning (clustering)
  • โœ… Business intelligence and actionable insights
  • โœ… Professional documentation and version control

โญ If you find this project helpful, please give it a star!

Made with โค๏ธ by Prabhat

About

This project analyzes online store data to understand customer buying behavior, identify key patterns, segment customers, and generate insights that help improve marketing, retention, and revenue.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors