What Is K-Means Clustering? A Plain-Language Explanation
K-means is an unsupervised clustering algorithm that groups unlabeled data points into a chosen number of clusters, where each point belongs to the cluster with the nearest center, called a centroid.
The everyday intuition
Imagine sorting a pile of mixed items into a fixed number of groups by repeatedly placing each item near the closest group marker, then moving each marker to the middle of its group. K-means repeats these two moves until the markers settle.
How the two steps work
| Step | What happens |
|---|---|
| Assignment | Every point is assigned to the nearest centroid, usually using Euclidean distance |
| Update | Each centroid is moved to the average position of the points assigned to it |
The algorithm repeats assignment and update, and the within-cluster sum of squares decreases until the centroids stop moving or a stopping limit is reached.
Choosing the number of clusters
The value of k is set in advance. A common aid is the elbow method, which plots a measure of cluster tightness as k increases and looks for a point where adding more clusters gives little improvement.
Where it is commonly used
K-means is used for customer segmentation, document grouping, image compression, and exploratory analysis when labels are not available.
Honest caveats
Because the result depends on the starting centroids, runs can settle at different local optima, so practitioners often run several initializations. It also assumes roughly spherical, similar-sized clusters and may not fit irregular patterns well.
FAQ
What is a centroid?
The center point of a cluster, typically calculated as the mean of the points in it.
Is k-means supervised or unsupervised?
Unsupervised, because it works with unlabeled data and discovers structure rather than predicting a known label.
What is the elbow method?
A plot-based way to help choose k by finding where the tightness measure begins to level off.
Why run k-means more than once?
Different starting centroids can produce different local optima, so multiple runs help find a stable result.
Key takeaways
- K-means partitions unlabeled data into k clusters.
- It alternates between assigning points and updating centroids.
- k is chosen in advance, often with the elbow method.
- It is simple and fast but sensitive to initialization and cluster shape.
Continue with what is clustering and what is unsupervised learning.
Sources
Learn by doing
Read a guide, then practice with bite-sized AI lessons you can take offline.
Start learning free