❓ What is the Elbow Method?

K-Means requires us to specify K (the number of clusters) upfront. The Elbow Method helps us choose K systematically by plotting the Within-Cluster Sum of Squares (WCSS) for different K values.

WCSS measures how tightly packed each cluster is. As K increases, WCSS always decreases. But the rate of improvement slows — creating an "elbow" shape in the plot.
The elbow point — where the curve bends sharply — indicates the optimal K where adding more clusters yields diminishing returns.
Algorithm Steps:
1 For k = 1 to 10, fit KMeans
2 Record WCSS (model.inertia_)
3 Plot K vs WCSS
4 Find the elbow (inflection point)
5 Choose K at the elbow
💻 Code
Python 1 from sklearn.cluster import KMeans
2
3 wcss = [] # List to store WCSS per k
4
5 for k in range(1, 11):
6     km = KMeans(
7         n_clusters = k,
8         init = 'k-means++', # Smart init
9         n_init = 10,
10         random_state = 42,
11     )
12     km.fit(X_scaled) # Fit on scaled data
13     wcss.append(km.inertia_) # inertia_ = WCSS
WCSS vs Number of Clusters
📊 WCSS Values Table
k 12345678910
WCSS 400.0 269.7 157.7 108.9 65.6 55.1 44.9 37.2 32.4 30.0
Conclusion: At k=5, the WCSS curve bends significantly. Adding a 6th cluster provides only marginal improvement. Optimal K = 5