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
1386.37—
2188.23198.14
33.02185.21
42.011.01
51.840.17
61.120.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

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.

By the same builder: GitHub — theluckystrike BeLikeNative — Grammar AI EarlyThunder — Dev Blog Bug Bounty Reality Zovo — AI Dev Tools

Related Tools