Glossary

K-means clustering

A clustering algorithm that partitions data into k groups by repeatedly assigning points to the nearest of k cluster centers.

Also called: k-means

K-means is one of the most widely used clustering algorithms. Given a chosen number of clusters, k, it places k initial cluster centers, called centroids, then alternates between two steps: assigning every point to its nearest centroid, and recomputing each centroid as the mean of the points assigned to it. This repeats until assignments stop changing or a maximum number of iterations is reached.

Because it minimizes the average squared distance from points to their cluster's centroid, k-means tends to produce compact, roughly spherical clusters of similar size, and struggles with clusters of very different shapes or densities. The value of k must be chosen in advance, often using methods such as the "elbow" plot of within-cluster variance against k, and results depend on the random starting centroids, so it is standard practice to run the algorithm multiple times and keep the best result.

K-means is popular for customer segmentation, document grouping and image compression because it is fast and scales well to large datasets. Pitfalls include running it on unscaled features, where a variable with a larger numeric range dominates the distance calculation, and treating the chosen k as reflecting genuine structure rather than an arbitrary choice; combining it with dimensionality reduction first often produces more stable, interpretable clusters.

Last reviewed September 22, 2026

In the index now

Related terms

Related guides