LearningAlgorithmBeginner-friendly
K-Means — Clustering (Explained)
Learn K-means clustering: centroids, assignments, inertia, and how to pick k.
What you'll learn
- How K-means alternates between assignment and centroid update.
- Why scaling and initialization matter.
- How the “elbow method” helps pick k.
Goal: group points into k clusters
K-means chooses k centroids and assigns each point to the nearest centroid.
Then it updates centroids to be the mean of their assigned points and repeats until stable.
Why it can fail
K-means prefers spherical, similarly-sized clusters because it relies on Euclidean distance to centroids.
Bad initialization can lead to poor local minima; K-means++ helps a lot.
Picking k
The elbow method looks at inertia (within-cluster sum of squares) as k increases.
Choose k where extra clusters provide diminishing returns.
Key takeaways
- Scale features before K-means.
- Use K-means++ initialization if available.
- Best for roughly spherical clusters.
- Elbow method is a heuristic, not a guarantee.
Want more ML topics added here (SVM, Naive Bayes, CNN, PCA, Decision Trees)?
Browse Machine Learning ->