Click canvas to add points - press Initialize to start
55 points
K-Means Clustering
Click canvas to add points
Clusters (K)
K = 3 clusters3
234
Actions
Cluster Sizes
55 unassigned - press Initialize
Cluster 10
Cluster 20
Cluster 30
How It Works
K-Means alternates between assigning points to the nearest centroid and moving centroids to the center of their cluster. Initialization matters - try running multiple times to see different outcomes.
Steps: 1. Place K centroids (k-means++ heuristic) 2. Assign each point to nearest centroid 3. Move each centroid to cluster mean 4. Repeat until centroids stop moving
Legend
Unassigned point
Cluster 1 point
Cluster 2 point
Cluster 3 point
Centroid (star)
K-Means Clustering - Interactive Visualization
K-Means is the most widely used clustering algorithm in machine learning. It assigns each data point to the nearest centroid, then moves centroids to the center of their cluster - repeating until nothing changes. This interactive demo lets you watch each step, click to add points, and see how different initializations lead to different results.
Step through each iteration: assignment → centroid update → check convergence
Click the canvas to add custom data points and watch the clusters adapt
See Voronoi region boundaries - the decision boundaries K-Means creates
Try running multiple times with "Initialize" to see sensitivity to starting position
Inertia (within-cluster sum of squared distances) measures cluster quality
Used in: customer segmentation, image compression, feature quantization, recommendation systems
Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.