Visual explainer
Clustering
How grouping unlabelled points by nearest center works, and where you pick K and where it fails.
Unsupervised clustering discovers latent structure in data without target labels. When observations arrive with coordinates alone, grouping relies purely on geometric proximity. The objective is to partition the points into cohesive clusters such that distances between points within the same cluster are minimized, while separation between different clusters is maximized.
Nearest Center Wins
K-Means establishes initial centroids and assigns each point to the closest center using Euclidean distance:
Placing candidate centroids at and tests observation . The distance to the first center is , while the distance to the second center is . Because , point assigns to center . Cluster membership is governed strictly by comparative distance.
Assign, Then Move
Evaluating the full four-point fixture against initial centers and establishes the Voronoi partition threshold at the midpoint:
Observation falls below and forms Cluster 1 alone. Observations , , and exceed and assign to Cluster 2. This lopsided -versus- split is an expected consequence of arbitrary centroid initialization that the subsequent update step corrects.
Centers Chase Means
Once assignments are fixed, each centroid leaps directly to the empirical center of mass of its assigned members:
Center has member , remaining at . Center averages members :
Center jumps from to in a single recalculation, centering itself over its assigned data mass.
Error Collapses
In round 2, the midpoint moves to , cleanly grouping into Cluster 1 and into Cluster 2. Recalculating group means settles and . No observation changes assignment, signaling convergence. Total Within-Cluster Sum of Squares (WCSS) error collapses from an initial down to :
Stop At Elbow
Selecting the number of clusters requires balancing model parsimony against residual variance. Plotting inertia across values of reveals the elbow bend:
- : WCSS
- : WCSS (error drops by )
- : WCSS (diminishing return of )
Adding the second centroid captures almost all structured variance. Beyond , incremental clusters provide negligible benefit while adding unwarranted complexity.
Where It Breaks
Because K-Means optimizes distance to point centroids, it implicitly assumes convex, isotropic, spherical clusters separated by linear Voronoi hyperplanes. When presented with interleaved non-convex geometries—such as interlocking half-moon crescents—the linear boundary slices straight across both manifolds, erroneously combining opposite halves into arbitrary geometric hemispheres. Resolving non-linear continuous shapes requires density-based (DBSCAN) or spectral clustering algorithms.
The Quick Version
- Unsupervised clustering organizes unlabelled points from distance metrics alone.
- Point 9 joins center 2 because its distance of 7.0 beats 8.0.
- Voronoi midpoint partitioning initially splits points 1 against 3.
- The update step moves centroids to group means: c2 leaps from 2.0 to 7.0.
- Final settled centroids at 1.5 and 9.5 reduce total squared error from 113.0 to 1.0.
- The elbow plot bends sharply at K=2 (drop of -64.0 vs marginal -0.5 for K=3).
- Linear Voronoi boundaries bisect non-convex crescent manifolds, requiring density methods.