An AI-powered E-commerce Customer Segmentation System using advanced clustering algorithms
Features โข Installation โข Usage โข Algorithms โข Screenshots โข API
SegmentX is a production-grade customer segmentation application that leverages multiple machine learning algorithms to identify distinct customer groups based on their purchasing behavior. Upload your transactional data and get actionable insights within seconds.
- ๐ Real-time Analysis - Get clustering results in seconds, not hours
- ๐ง Multiple Algorithms - Automatically selects the best clustering approach
- ๐ Rich Visualizations - Interactive 2D/3D PCA plots, distribution charts, and more
- ๐ผ RFM Analysis - Recency, Frequency, Monetary analysis for marketing insights
- ๐ Sales Analytics - Comprehensive sales performance metrics
- ๐จ Modern UI - Beautiful glassmorphism design with animations
The system tries multiple clustering algorithms and configurations to find the optimal customer segments:
| Algorithm | Description |
|---|---|
| KMeans | Classic partitioning with multiple k values |
| Mini-Batch KMeans | Optimized for large datasets |
| Spectral Clustering | Excellent for non-convex clusters |
| Agglomerative | Hierarchical clustering approach |
| Gaussian Mixture Model | Handles overlapping clusters |
| BIRCH | Efficient for large datasets |
| HDBSCAN | Density-based, noise-resistant (optional) |
Automatically segments customers based on:
- Recency - How recently a customer made a purchase
- Frequency - How often they purchase
- Monetary - How much they spend
Customer segments include: Champions, Loyal Customers, Potential Loyalists, New Customers, At Risk, and more.
- 2D & 3D PCA Scatter Plots - Visualize cluster separation
- Cluster Distribution - See customer count per segment
- Feature Distributions - Understand spending patterns
- Correlation Heatmaps - Identify feature relationships
- Silhouette Analysis - Measure cluster quality
- Python 3.8 or higher
- pip (Python package manager)
-
Clone the repository
git clone https://github.com/AshishCh01/SegmentX.git cd SegmentX -
Create a virtual environment (recommended)
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Run the application
python app.py
-
Open in browser
http://localhost:5000
For density-based clustering with noise resistance:
pip install hdbscan>=0.8.29Your CSV file should contain customer transaction data with columns like:
- Customer ID (optional - auto-detected)
- Purchase Amount / Spending
- Number of Items / Quantity
- Purchase Date (for RFM analysis)
- Any other numerical features
Example CSV format:
CustomerID,TotalSpending,NumItems,Frequency,AvgOrderValue
C001,1500.00,25,12,125.00
C002,450.50,8,3,150.17
C003,3200.00,45,24,133.33- Navigate to
http://localhost:5000 - Drag and drop your CSV file or click to browse
- Click "Analyze Customers"
- Review the segmentation results and visualizations
- Download the clustered data with segment labels
SegmentX/
โโโ app.py # Main Flask application
โโโ requirements.txt # Python dependencies
โโโ runtime.txt # Python version specification
โ
โโโ analysis/ # Analysis modules
โ โโโ __init__.py
โ โโโ preprocessing.py # Data preprocessing & cleaning
โ โโโ clustering.py # Advanced clustering engine
โ โโโ rfm_analysis.py # RFM segmentation
โ โโโ sales_analytics.py # Sales performance metrics
โ
โโโ templates/ # HTML templates
โ โโโ index.html # Upload page
โ โโโ result.html # Results dashboard
โ
โโโ static/ # Static assets
โ โโโ uploads/ # Uploaded files & generated plots
โ
โโโ data/ # Sample datasets
โโโ amazon.csv
โโโ customer_shopping_data.csv
โโโ sample_customers.csv
-
Data Preprocessing
- Handle missing values
- Remove duplicates
- Normalize/standardize features
- Outlier detection (IQR method)
-
Feature Engineering
- Create derived features (e.g., spending ratios)
- PCA for dimensionality reduction
- Feature selection based on variance
-
Algorithm Selection
- Run multiple algorithms in parallel
- Evaluate using Silhouette Score
- Select configuration with best separation
-
Labeling
- Assign meaningful segment names
- Generate descriptive statistics per cluster
| Metric | Description |
|---|---|
| Silhouette Score | Measures cluster cohesion and separation (-1 to 1) |
| Davies-Bouldin Index | Lower values indicate better clustering |
| Calinski-Harabasz Index | Higher values indicate better-defined clusters |
Renders the upload page.
Analyzes the uploaded CSV file.
Request:
- Content-Type:
multipart/form-data - Body:
file(CSV file)
Response: Renders result page with:
- Cluster assignments
- Visualization plots
- Segment statistics
- Downloadable clustered CSV
When you run the analysis, you'll get:
- Cluster Distribution Chart - Visual breakdown of customer segments
- 2D PCA Plot - Scatter plot showing cluster separation
- 3D PCA Plot - Interactive 3D visualization
- Feature Importance - Which features drive segmentation
- Segment Profiles - Detailed statistics for each customer group
Contributions are welcome! Here's how you can help:
- 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.
- scikit-learn - Machine learning library
- Flask - Web framework
- Pandas - Data manipulation
- Matplotlib & Seaborn - Visualizations
- TailwindCSS - UI styling
Built with โค๏ธ for data-driven business decisions