K-means is an unsupervised algorithm: it is handed a cloud of
points with no labels and asked to sort them into K groups. Here each
point lives in a 3D feature space. Colored spheres are the data; the larger glowing
orbs are the centroids — the current best guess at each cluster's
center.
Because k-means always converges to a local minimum of inertia, real-world use runs it many times from different random starts (or uses smarter seeding like k-means++) and keeps the run with the lowest inertia.
A 3D cloud of unlabeled points, colored live by which of K glowing centroids they're currently closest to, as Lloyd's algorithm alternates between assigning points and re-centering centroids until it converges.
Each iteration re-assigns every point to its nearest centroid, then moves each centroid to the mean of its assigned points. Inertia (total squared distance) only ever decreases, and the process settles into a local optimum.
Pick how many clusters K the algorithm should look for, how many true blobs actually generated the data, and how many points to scatter. Step through iterations manually or let it auto-run, then regenerate fresh data.
Set K far from the true number of blobs and watch what happens — too few clusters merges distinct groups, too many splits a single natural group into fragments. Choosing K is genuinely part of the art of clustering.