📅 Quick Reference · AI Algorithms
K-MEANS = Assign to nearest CENTROID, move centroid, repeat until stable
K-means clustering — the three-step dance
1
Assign — place points with their nearest centroid
After K centroids are initially placed (often randomly), every data point is assigned to whichever centroid is currently closest to it.
Example: a customer's data point gets assigned to cluster 3 because centroid 3 is currently the nearest of the K centroids.
2
Update — move centroids to the average position
Each centroid is recalculated as the mean position of all points currently assigned to it, moving it toward the center of its current cluster.
Example: if five customers are currently assigned to cluster 2, that cluster's centroid moves to the average position of those five customers.
3
Converge — repeat until centroids stop moving
Steps 1 and 2 repeat over and over until the centroids stop moving significantly between rounds, indicating the clusters have stabilized into their final form.
Example: after 15 rounds of reassigning points and updating centroids, the centroids stop changing meaningfully — the algorithm has converged.
1
A retailer wants to segment customers into groups based on purchasing behavior, but has to decide on the number of clusters (K) upfront.
2
This upfront requirement to specify K is a known weakness of K-means — the elbow method (plotting inertia against different values of K) is commonly used to choose a reasonable value.
3
Once K is chosen, the assign-update-converge dance runs repeatedly until the centroids stabilize into their final positions.
4
The resulting stable clusters can then be used for tasks like customer segmentation, document grouping, or image compression — all common K-means applications.

Exams test whether you can correctly sequence the three K-means steps (assign, update, converge) and whether you know the key weakness: K must be specified in advance, unlike some alternative clustering methods.

The most common trap is forgetting that K-means requires specifying the number of clusters (K) before running the algorithm — it does not discover the "right" number of clusters on its own, unlike density-based alternatives like DBSCAN.

1. What happens during the "assign" step of K-means?
Every data point is assigned to whichever centroid is currently closest to it.
Tap to reveal / hide
2. What happens during the "update" step of K-means?
Each centroid is recalculated as the mean position of all points currently assigned to it.
Tap to reveal / hide
3. How do you know K-means has converged?
When the centroids stop moving significantly between rounds.
Tap to reveal / hide
4. What must be specified before running K-means, which is considered a weakness?
The number of clusters, K, must be chosen in advance.
Tap to reveal / hide
5. Name one real-world application of K-means clustering.
Customer segmentation, document grouping, or image compression.
Tap to reveal / hide