Lesson 2 of 4 10 min · 145 words
k-means
Alternate assigning points and moving centroids.
k-means partitions the data into clusters, each represented by its centroid , by minimising the within-cluster sum of squares:
Lloyd's algorithm alternates two steps until assignments stop changing:
- Assign: put each point in the cluster of its nearest centroid.
- Update: move each centroid to the mean of its assigned points.
Each step can only lower , so it always converges — but possibly to a poor local minimum. Run it several times from different starts, and use k-means++ initialisation, which spreads the initial centroids out.
Choosing : plot against and look for the elbow where improvement flattens, or pick the with the best average silhouette.
Formula to remember
Silhouette
Near 1 means well clustered.
Quick check · +5 XP