🎯
5
Clusters (K)
📊
0.5547
Silhouette Score
🔄
300
Max Iterations
66
Final WCSS
⚙️ How K-Means Works
1
Initialise

Place K centroids randomly (k-means++ places them smart — far apart) to seed the algorithm.

2
Assign

Each customer is assigned to the nearest centroid using Euclidean distance.

3
Update

Recompute each centroid as the mean of all customers in that cluster.

4
Repeat

Steps 2–3 are repeated until centroids stop moving (convergence) or max_iter is reached.

5
Evaluate

The final WCSS and Silhouette Score confirm cluster quality.

💻 Final Model Code
Python 1 from sklearn.cluster import KMeans
2 import joblib
3
4 # Instantiate with k-means++ initialisation
5 km = KMeans(
6     n_clusters = 5, # Optimal K from Elbow
7     init = 'k-means++', # Smart seeding
8     n_init = 10, # Run 10 times, pick best
9     random_state = 42, # Reproducibility
10     max_iter = 300, # Safety limit
11 )
12 km.fit(X_scaled) # Train on scaled data
13 df['Cluster'] = km.labels_ # Add labels to df
14 joblib.dump(km, 'kmeans_model.pkl') # Save model
📍 Cluster Centroids (Scaled Space)
ClusterIncome (z)Spending (z)
C0 -0.201 -0.026
C1 0.992 1.240
C2 -1.330 1.132
C3 1.055 -1.284
C4 -1.308 -1.137
📉 Silhouette Score Analysis
Silhouette Score vs Number of Clusters

Silhouette Score measures cluster separation and compactness on a scale from -1 to +1. Higher values indicate better-defined segments.

s(i) = (b − a) / max(a, b)
a = intra-cluster distance · b = nearest-cluster distance
kSilhouette ScoreQuality
2 0.3213 Good
3 0.4666 Excellent
4 0.4939 Excellent
5 0.5547 Excellent
6 0.5399 Excellent
7 0.5281 Excellent
8 0.4552 Excellent
9 0.4571 Excellent
10 0.4432 Excellent
📊 Cluster Summary Statistics
ClusterCustomersShare % Avg AgeAvg Income (k$)Avg Spending MalesFemales
Cluster 0 81
40.5%
42.7 55.3 49.5 33 48
Cluster 1 39
19.5%
32.7 86.5 82.1 18 21
Cluster 2 22
11.0%
25.3 25.7 79.4 9 13
Cluster 3 35
17.5%
41.1 88.2 17.1 19 16
Cluster 4 23
11.5%
45.2 26.3 20.9 9 14