Customer segmentation is a technique used by businesses to divide customers into different groups based on their characteristics and purchasing behavior.
This project focuses on analyzing mall customer data and creating meaningful customer segments using Unsupervised Machine Learning (K-Means Clustering).
The objective is to identify customer groups based on their income and spending patterns, helping businesses understand customer behavior and design targeted marketing strategies.
Retail businesses often have customers with different purchasing behaviors. Treating all customers equally can lead to ineffective marketing campaigns.
The goal of this project is to:
- Analyze customer characteristics
- Identify hidden customer groups
- Apply clustering techniques
- Generate business insights from customer segments
The dataset contains information about mall customers.
| Feature | Description |
|---|---|
| CustomerID | Unique customer identifier |
| Gender | Customer gender |
| Age | Customer age |
| Annual Income | Customer annual income |
| Spending Score | Score assigned based on customer spending behavior |
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-learn
- Data Preprocessing
- Exploratory Data Analysis (EDA)
- Feature Scaling
- Principal Component Analysis (PCA)
- K-Means Clustering
- Elbow Method
ββββββββββββββββββββββββββ
β Load Dataset β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Data Exploration (EDA) β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Data Preprocessing β
β β’ Check Missing Values β
β β’ Select Features β
β β’ Feature Scaling β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Feature Selection β
β (Income & Spending) β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Find Optimal K β
β (Elbow Method) β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Train K-Means Model β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Assign Cluster Labels β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Visualize Clusters & β
β Centroids β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Analyze Customer β
β Segments β
ββββββββββββ¬ββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β Business Insights & β
β Recommendations β
ββββββββββββββββββββββββββ
Imported the mall customer dataset and performed initial data inspection.
Performed:
- Checking missing values
- Checking duplicate records
- Understanding data types
- Handling unnecessary columns
Analyzed customer behavior using:
- Distribution plots
- Scatter plots
- Box plots
- Correlation analysis
Key patterns were identified between:
- Annual Income
- Spending Score
- Age
The Elbow Method was used to determine the optimal number of customer clusters.
Customers were successfully grouped into different clusters based on Annual Income and Spending Score.
Selected important features for clustering:
- Annual Income
- Spending Score
Applied:
- StandardScaler for normalization
- PCA for dimensionality reduction and visualization
K-Means is an unsupervised machine learning algorithm that groups similar data points into clusters.
- Select number of clusters
- Initialize cluster centroids
- Assign data points to nearest centroid
- Update centroid positions
- Repeat until clusters stabilize
The Elbow Method was used to determine the optimal number of clusters.
The method calculates Within-Cluster Sum of Squares (WCSS) for different values of K.
The point where the decrease in WCSS slows down represents the ideal number of clusters.
Based on clustering results, customers were divided into different groups:
Characteristics:
- High purchasing power
- Premium customers
- Valuable for targeted offers
Business Strategy:
- Loyalty programs
- Premium product recommendations
Characteristics:
- High earning customers
- Lower purchase frequency
Business Strategy:
- Personalized promotions
- Engagement campaigns
Characteristics:
- Frequent shoppers
- Strong brand engagement
Business Strategy:
- Customer retention programs
Characteristics:
- Limited spending behavior
Business Strategy:
- Budget-friendly offers
The project includes:
- Customer distribution analysis
- Correlation heatmap
- Income vs Spending Score analysis
- Elbow curve visualization
- Cluster visualization
- PCA-based cluster representation
The analysis helps businesses to:
- Understand different customer groups
- Create personalized marketing campaigns
- Improve customer retention
- Identify premium customers
- Optimize business strategies
Through this project, I gained practical experience in:
- Python Programming
- Data Cleaning
- Exploratory Data Analysis
- Data Visualization
- Feature Engineering
- Data Scaling
- PCA
- Unsupervised Machine Learning
- K-Means Clustering
- Business Insight Generation
Mall-Customer-Segmentation
β
βββ Dataset
β βββ Mall_Customers.csv
β
βββ Images
β βββ Correlation_Matrix.png
β βββ Cluster_Centroids.png
β βββ Customer_segmentation.png
β
βββ Mall_Customer_Segmentation.ipynb
β
βββ README.md
β
βββ requirements.txt
Possible improvements:
-
Correlation Matrix (Feature Correlation Analysis)
-
Try advanced clustering algorithms:
- DBSCAN
- Hierarchical Clustering
-
Deploy the model using:
- Streamlit
- Flask
-
Build an interactive customer segmentation dashboard using:
- Power BI
- Tableau
Anuj Bhatt
GitHub: https://github.com/anujbhatt30
If you found this project useful, consider giving it a β on GitHub.


