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.
- ๐ 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
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
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
- Load raw e-commerce transaction data
- Handle missing values, duplicates, and data type conversions
- Validate data integrity and consistency
- Analyze customer demographics and purchase patterns
- Visualize distributions of orders, revenue, and products
- Identify trends and anomalies in the data
- Create customer-level aggregated metrics
- Calculate RFM scores:
- Recency: Days since last purchase
- Frequency: Total number of orders
- Monetary: Total amount spent
- Apply K-Means clustering on RFM features
- Identify optimal number of clusters using Elbow Method and Silhouette Score
- Label segments with business-friendly names
- Analyze characteristics of each segment
- Provide targeted marketing strategies
- Calculate segment revenue contribution
| 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 |
| 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 |
๐ 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
# Python 3.8 or higher
python --version
# Install pip if not already installed
pip --version- Clone the repository
git clone https://github.com/13-Prabhat/E-commerce-Customer-Behavior-Analysis-Segmentation.git
cd E-commerce-Customer-Behavior-Analysis-Segmentation- Create a virtual environment (optional but recommended)
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Launch Jupyter Notebook
jupyter notebook- Run notebooks in sequence
- Start with
01_data_loading_cleaning.ipynb - Follow the numbered order for best results
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
Contributions are welcome! If you'd like to improve this project:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Prabhat
- GitHub: @13-Prabhat
- Project Link: E-commerce Customer Behavior Analysis
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