K-Means Clustering

Harvard EPS-210 | Interactive tutorial — Explore unsupervised learning with iterative centroid optimization

Clustering Space

Unassigned
Centroid
Centroid Trail

Voronoi Regions

Assign xᵢ to argmin_k ||xᵢ - μₖ||²
Each point joins nearest centroid

Inertia (Within-Cluster SS)

Elbow Method

J = Σₖ Σᵢ∈Cₖ ||xᵢ - μₖ||²
Total within-cluster variance

Data Points

Click on the clustering canvas to add points

Number of Clusters (K)

3
Clusters

Algorithm Control

0
Iteration
Ready

Statistics

Total Points
0
Inertia
--

Quick Examples

How it works: K-Means alternates between (1) assigning each point to its nearest centroid, and (2) updating centroids to the mean of assigned points. It converges when assignments no longer change.