Interactive K-Means Clustering Explorer
Browser-based two-dimensional K-Means laboratory comparing random and K-Means++ initialization, step-by-step centroid convergence, and within-cluster sum of squares (WCSS).
How the Explorer Works
K-Means partitions observations in into clusters by alternating between two steps until assignments stabilize:
- Assignment Step: Each point joins the nearest centroid under Euclidean distance .
- Update Step: Each centroid moves to the arithmetic mean of all points currently assigned to cluster .
Why Initialization Matters
Standard Random initialization places initial centroids uniformly across existing data points and can become trapped in poor local optima (especially when multiple centroids start inside the same dense cluster). K-Means++ selects initial centroids sequentially with probability proportional to —the squared distance to the closest already-chosen centroid—dramatically improving convergence stability and lowering final within-cluster sum of squares (WCSS).
Experiments to Try
- Switch between Gaussian Blobs and Two Moons to observe where Euclidean centroid geometry succeeds versus where non-convex manifolds break linear Voronoi boundaries.
- Compare Random vs. K-Means++ on the Anisotropic preset at .
- Tap or click directly on the plot canvas to inject custom outlier points and step through centroid drift.