Content
You are owing a supermarket mall and through membership cards ,
you have some basic data about your customers like Customer ID,
age, gender, annual income and spending score. Spending Score is
something you assign to the customer based on your defined
parameters like customer behavior and purchasing data.
Problem Statement
You own the mall and want to understand the customers like who
can be easily converge [Target Customers] so that the sense can
be given to marketing team and plan the strategy accordingly.
Warning: Looks like you're using an outdated `kagglehub` version (installed: 0.3.13), please consider upgrading to the latest version (0.4.2). Files: ['Mall_Customers.csv']
| CustomerID | Gender | Age | Annual Income (k$) | Spending Score (1-100) | |
|---|---|---|---|---|---|
| 0 | 1 | Male | 19 | 15 | 39 |
| 1 | 2 | Male | 21 | 15 | 81 |
| 2 | 3 | Female | 20 | 16 | 6 |
EDA¶
Scale Data¶
Find the Optimal K¶
Elbow method¶
Silhouette Score Method¶
K=2, Silhouette Score=0.3355 K=3, Silhouette Score=0.3579 K=4, Silhouette Score=0.4040 K=5, Silhouette Score=0.4085 K=6, Silhouette Score=0.4311 K=7, Silhouette Score=0.4101 K=8, Silhouette Score=0.3674 K=9, Silhouette Score=0.3744 K=10, Silhouette Score=0.3619
The optimal number of clusters is 6
C:\Users\syarn\AppData\Local\Temp\ipykernel_31460\3546621768.py:8: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed in 3.11. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()`` or ``pyplot.get_cmap()`` instead.
cmap = cm.get_cmap('tab10') # supports up to 10 distinct colors
The analysis indicates 6 as the optimal number of clusters, so we segment the customers into six groups.
| Age | Annual Income (k$) | Spending Score (1-100) | Cluster | |
|---|---|---|---|---|
| 0 | 19 | 15 | 39 | 4 |
| 1 | 21 | 15 | 81 | 4 |
| 2 | 20 | 16 | 6 | 5 |
| 3 | 23 | 16 | 77 | 4 |
| 4 | 31 | 17 | 40 | 5 |