60-second card
Clustering
Clustering groups similar points without labels. k-means finds k groups around centres.
- Assign each point to the nearest centre.
- Move each centre to the mean of its points. Repeat until stable.
- Choose k with the elbow method or silhouette score.
import numpy as np
cluster = np.array([[1, 2], [3, 4], [5, 6]])
print(cluster.mean(axis=0).tolist())Prints
[3.0, 4.0]Remember: Scale features first: clustering uses distances.
Common mistake: Using k-means on ring or curved shapes. Try DBSCAN for those.