How Do I Choose K in K-Means Clustering?
Compute WCSS for several values of K, plot it, and pick the K where the curve bends and then flattens. If no clear bend appears, compare the cluster sizes against the problem itself, check that assignments stay stable across random restarts, and use a silhouette score as a second opinion.
What WCSS Measures
WCSS is the within-cluster sum of squares. For every point, take its squared distance to the centroid of the cluster it belongs to, then add those values over all points:
WCSS = sum over clusters k of sum over points x in k of ||x - mu_k||^2
A lower WCSS means tighter clusters. That does not make it a score to minimise: WCSS always falls as K grows, because more centroids can only shorten the distances. When K equals the number of points, WCSS is exactly 0 and the clustering says nothing.
Run the Curve
The table below is a measured run. The data is 12 points in three well-separated groups. K-means ran with 5 random restarts for each K, and the table shows the best (lowest) WCSS for that K.
| K | WCSS | Drop from the row above |
|---|---|---|
| 1 | 386.37 | — |
| 2 | 188.23 | 198.14 |
| 3 | 3.02 | 185.21 |
| 4 | 2.01 | 1.01 |
| 5 | 1.84 | 0.17 |
| 6 | 1.12 | 0.72 |
Read the Elbow
Between K=2 and K=3 the WCSS falls by 185.21. Between K=3 and K=4 it falls by only 1.01. The slope changes sharply at K=3, so K=3 is the elbow and the value to pick. The three groups in the data are exactly what the cut at K=3 recovers.
Read the drop column, not the WCSS column. A small WCSS at K=6 (1.12) is lower than the WCSS at K=3 (3.02), but K=6 spends three extra centroids to remove 1.90 units of error. That is the trade the elbow method makes visible.
When the Elbow Is Unclear
- Silhouette score. For each point, compare its mean distance to its own cluster (a) with its mean distance to the nearest other cluster (b). The score is (b - a) / max(a, b) and runs from -1 to 1. Average it per K and take the K with the highest mean; this does not depend on the WCSS scale.
- Stability across restarts. Run k-means with different seeds and compare the final assignments. If K=4 gives a different partition on every seed while K=3 repeats, K=3 is the better answer.
- Domain limits. If the clusters will be acted on by a person, a K that produces one cluster of 2 points and one of 400 points is usually wrong even when its WCSS is low.
Use the ML3X Elbow Helper
The K-Means clustering tool plots 2D points that you click. Its elbow helper runs k-means for K=1 to K=8 on the current points with 5 random restarts per K, keeps the lowest WCSS for each K, and prints one WCSS line per K. The K buttons on the tool cover 2 to 8, so the helper is the only place K=1 appears.