◆ Algo3DVerse AI/ML
04 · Unsupervised
AI/ML Visual Lesson 04

K-Means
Clustering

No labels needed. Drop K centroids into unlabeled data, assign each point to the nearest one, move centroids to the mean — repeat until stable.

K-Means is the most widely used clustering algorithm. It partitions data into K groups by iterating two simple steps: assign each point to its nearest centroid, then move each centroid to the mean of its assigned points. It repeats until centroids stop moving — convergence. The algorithm is fast, simple, and scales to millions of points.

Algorithm, live

White spheres are unlabeled data. Step through the assign → update loop and watch clusters emerge from nothing.

Drag to rotate · scroll to zoom
ITERATION 0
PHASE     —
INERTIA   —
K-Means step through the algorithm
K = 3

How K-Means works

Three steps. Two of them alternate until nothing changes.

🎯

1 · Initialise

random placement

Place K centroids at random positions in the data space. The choice of starting positions affects which solution is found — K-Means++ improves this with a smarter spread.

📌

2 · Assign

nearest centroid · Euclidean

For every data point, compute the distance to each centroid and assign the point to the closest one. This partitions the space into Voronoi regions.

📍

3 · Update

mean of cluster

Move each centroid to the mean (average) of all points currently assigned to it. Points may change clusters in the next assign step because centroids moved.

✅

Convergence

inertia · stopping criterion

Repeat assign and update until no point changes cluster between iterations. The algorithm is guaranteed to converge — but not necessarily to the global optimum.