Data Mining & Visualization
Online B.Com · Sem 5
0% complete
0/5 lessons
Lesson 3 of 5Analytics
K-Means Clustering
Data Mining & Visualization
About the video
StatQuest: K-means clustering
StatQuest with Josh Starmer
Study notes
K-means is an unsupervised algorithm that partitions data into k clusters by alternately assigning points to the nearest centroid and recomputing centroids. It minimises the within-cluster sum of squares. The choice of k, feature scaling, and initialisation all strongly affect the results.
Algorithm
- 1. Choose k and initialise k centroids (randomly or with k-means++).
- 2. Assign each point to its nearest centroid, usually by Euclidean distance.
- 3. Recompute each centroid as the mean of its assigned points.
- 4. Repeat steps 2-3 until assignments stop changing.
- Objective: minimise WCSS = sum of squared distances from each point to its centroid.
Choosing k
- Elbow method: plot WCSS against k and pick the bend where improvement slows.
- Silhouette score: ranges from -1 to 1, and higher means better separated clusters.
- WCSS always decreases as k grows, so the smallest WCSS alone is not a valid way to choose k.
Practical issues
- Scale (standardise) features, because distance is dominated by large-scale variables.
- The algorithm converges to a local optimum, so run it with multiple initialisations.
- It assumes roughly spherical, similar-size clusters and is sensitive to outliers.
- It needs numeric data, because centroids are means.
Key terms
- Centroid
- The mean point of a cluster.
- WCSS / inertia
- The within-cluster sum of squared distances.
- Elbow method
- A heuristic that chooses k at the bend of the WCSS-versus-k curve.
- k-means++
- A smart initialisation that spreads out the initial centroids.
- Silhouette score
- A measure of how well each point fits its own cluster compared with the nearest other cluster.
Takeaways
- K-means alternates assignment and update steps.
- Standardise features before clustering.
- Choose k with the elbow method or silhouette score, not minimum WCSS.
- Results depend on initialisation, so use multiple runs or k-means++.
Contribute
Was this lesson helpful?
We read every rating and fix the weakest lessons first.