k-means clustering
Step through assign-and-update until the centroids stop moving.
Step through assign-and-update until the centroids stop moving.
k-means groups unlabelled points into k clusters by repeating two steps: assign each point to its nearest centroid, then move each centroid to the average of its points. Each step can only lower the inertia, so the algorithm always settles down, usually within a few iterations.
It settles in a local minimum, though, so a bad starting position can split one blob in two and merge two others. In practice we run it several times from different starts and keep the lowest inertia. To choose k, plot inertia against k and look for the “elbow” where adding a cluster stops helping much.
Assign colours every point by its nearest centroid. Update moves each centroid to the mean of its points. Tap the plot to grab the nearest centroid and drag it somewhere silly.
k-means groups unlabelled points into k clusters by repeating two steps: assign each point to its nearest centroid, then move each centroid to the average of its points. Each step can only lower the inertia, so the algorithm always settles down, usually within a few iterations.
It settles in a local minimum, though, so a bad starting position can split one blob in two and merge two others. In practice we run it several times from different starts and keep the lowest inertia. To choose k, plot inertia against k and look for the “elbow” where adding a cluster stops helping much.
Things to try