Skip to content

About

Comparative analysis of K-Means, K-Medoids, DBSCAN, and Gaussian Mixture Model clustering algorithms for mall customer segmentation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Mall Customer Clustering Comparison

📌 Project Overview

This project applies and compares four unsupervised machine learning algorithms for mall customer segmentation based on Annual Income and Spending Score.

The main objective is to identify meaningful customer groups and determine which clustering algorithm provides the best segmentation performance for the dataset.

The following clustering algorithms were implemented and evaluated:

  • K-Means
  • K-Medoids
  • DBSCAN
  • Gaussian Mixture Model (GMM)

The models were evaluated using three internal clustering validation metrics:

  • Silhouette Score — Higher is better
  • Davies-Bouldin Index (DBI) — Lower is better
  • Calinski-Harabasz Index (CH) — Higher is better

🎯 Project Objective

The objective of this project is to:

  1. Explore the structure of mall customer data.
  2. Apply different unsupervised clustering algorithms.
  3. Determine the optimal number of clusters for K-Means.
  4. Compare K-Means, K-Medoids, DBSCAN, and GMM.
  5. Evaluate clustering quality using multiple performance metrics.
  6. Identify the best-performing algorithm for customer segmentation.

📊 Dataset

The project uses the Mall Customer Segmentation Dataset, which contains information about mall customers.

The main features used for clustering are:

  • Annual Income (k$)
  • Spending Score (1–100)

These features were selected to identify groups of customers based on their income level and spending behavior.


🤖 Algorithms Used

1. K-Means

K-Means partitions customers into a predefined number of clusters by minimizing the within-cluster sum of squares.

The Elbow Method and Silhouette Score were used to determine the optimal number of clusters.

The analysis selected:

Optimal K = 5


2. K-Medoids

K-Medoids is similar to K-Means but uses actual observations as cluster representatives (medoids). It is generally more robust to outliers than K-Means.

For this analysis, K-Medoids was evaluated using:

K = 5


3. DBSCAN

DBSCAN is a density-based clustering algorithm that identifies clusters based on the density of data points. Unlike K-Means and K-Medoids, DBSCAN does not require the number of clusters to be specified in advance.

It can also identify noise or outlier observations.


4. Gaussian Mixture Model (GMM)

Gaussian Mixture Model is a probabilistic clustering approach that assumes the data is generated from a mixture of Gaussian distributions.

For this analysis, GMM was configured with:

5 Gaussian Components


📈 Model Evaluation

The clustering algorithms were evaluated using three metrics.

Algorithm Silhouette Score ↑ Davies-Bouldin Index ↓ Calinski-Harabasz Index ↑
K-Means 0.5547 0.5722 248.6493
Gaussian Mixture 0.5537 0.5760 244.9402
K-Medoids 0.4016 0.8383 102.5266
DBSCAN 0.3876 0.7889 85.3897

Metric Interpretation

  • Silhouette Score: Higher values indicate better-defined and well-separated clusters.
  • Davies-Bouldin Index: Lower values indicate more compact and better-separated clusters.
  • Calinski-Harabasz Index: Higher values indicate better-defined clusters with greater separation between groups.

🏆 Overall Ranking

The algorithms were ranked based on their performance across all three evaluation metrics.

Algorithm Silhouette Rank DBI Rank CH Rank Overall Rank
🥇 K-Means 1 1 1 1
🥈 Gaussian Mixture 2 2 2 2
🥉 K-Medoids 3 4 3 3
DBSCAN 4 3 4 4

🔍 Key Findings

  • K-Means achieved the best overall clustering performance.
  • K-Means obtained the highest Silhouette Score (0.5547).
  • K-Means achieved the lowest Davies-Bouldin Index (0.5722).
  • K-Means achieved the highest Calinski-Harabasz Index (248.6493).
  • Gaussian Mixture Model performed very closely to K-Means, making it a strong alternative.
  • K-Medoids and DBSCAN produced lower scores across the evaluation metrics.
  • The results suggest that the Mall Customer dataset is well suited to the compact and relatively well-separated clusters identified by K-Means.

✅ Final Conclusion

Four unsupervised learning algorithms—K-Means, K-Medoids, DBSCAN, and Gaussian Mixture Model—were evaluated for segmenting mall customers based on Annual Income and Spending Score.

The results demonstrate that K-Means is the best-performing algorithm for this dataset. It achieved the highest Silhouette Score, the lowest Davies-Bouldin Index, and the highest Calinski-Harabasz Index, ranking first across all three evaluation metrics.

The Gaussian Mixture Model (GMM) ranked second and performed very closely to K-Means. This indicates that GMM is also capable of producing meaningful customer segments. However, K-Means remains the preferred model due to its slightly better performance, simplicity, and interpretability.

Therefore, K-Means with five clusters (K = 5) is selected as the final clustering approach for this mall customer segmentation analysis.


🛠️ Technologies and Tools

  • Python
  • Jupyter Notebook
  • Pandas
  • NumPy
  • Matplotlib
  • Seaborn
  • Scikit-learn
  • Scikit-learn-extra
  • Gaussian Mixture Models
  • K-Means
  • K-Medoids
  • DBSCAN

📁 Project Structure

mall-customer-clustering-comparison/
│
├── mall_customer_clustering_comparison.ipynb
├── README.md
└── dataset/
    └── Mall_Customers.csv

🚀 How to Run

1. Clone the repository

git clone https://github.com/21Oli/mall-customer-clustering-comparison.git

2. Navigate to the project directory

cd mall-customer-clustering-comparison

3. Install the required libraries

pip install pandas numpy matplotlib seaborn scikit-learn scikit-learn-extra jupyter

4. Launch Jupyter Notebook

jupyter notebook

5. Open the notebook

mall_customer_clustering_comparison.ipynb

Run the notebook cells sequentially to reproduce the analysis and results.


📌 Future Improvements

Possible future improvements include:

  • Testing additional clustering algorithms.
  • Performing hyperparameter optimization for DBSCAN.
  • Using additional customer features.
  • Applying dimensionality reduction techniques such as PCA.
  • Visualizing customer segments using interactive dashboards.
  • Developing a customer segmentation dashboard using Streamlit.
  • Analyzing the business characteristics of each identified customer segment.

👨‍💻 Author

Oli Bakala

Data Science & AI Enthusiast | Software Engineering Graduate


⭐ Conclusion

This project demonstrates how different unsupervised learning algorithms can be applied to customer segmentation and compared using multiple clustering evaluation metrics.

The final analysis shows that K-Means with K = 5 provides the strongest overall clustering performance for the Mall Customer dataset.

About

Comparative analysis of K-Means, K-Medoids, DBSCAN, and Gaussian Mixture Model clustering algorithms for mall customer segmentation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages