← Lesson
BitWithBite
AI & Machine Learning · Quick Reference

lesson-4.1 Cheat Sheet

AI & Machine Learning
In one line: K-Means partitions data into k clusters by alternating two steps until convergence — this is Lloyd's algorithm:

Key Ideas

1Why initialization matters. K-Means converges to a local minimum, not necessarily the global one. Random initialization can land centroids badly — e.g. two centroids starting in the same true clu...
2Convergence and local minima. Each iteration of assign-then-update can only decrease (or hold steady) the total within-cluster distance, so the algorithm always converges — but where it converges d...

Code Examples

from sklearn.cluster import KMeans km = KMeans(n_clusters=3, init='k-means++', n_init=10, random_state=42) km.fit(X) km.labels_ # cluster assignment per point km.cluster_centers_ # final centroid coordinates