🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #147

K-Means Elbow Method

The elbow method picks a reasonable value of \(k\) for K-Means by plotting WCSS against \(k\) and looking for the point where adding more clusters stops meaningfully reducing it.

Why WCSS Alone Can't Just Be Minimized

WCSS always decreases as \(k\) increases — in the extreme, \(k=n\) (one cluster per point) gives WCSS of exactly 0. Minimizing WCSS directly would always favor more clusters, which defeats the purpose of clustering (finding a small number of meaningful groups). The elbow method instead looks for diminishing returns — the point where each additional cluster buys much less WCSS reduction than the ones before it.

Worked Example — Continuing the 6-Point Dataset

kWCSSDrop From Previous k
170.0
216.054.0 (huge drop)
3~8.0~8.0 (much smaller drop)
4~4.0~4.0 (smaller still)

At \(k=1\), all 6 points are forced into one cluster centered at the overall mean \((5,4)\), giving \(WCSS = 70\) (a large number, since the two groups are far apart). At \(k=2\), WCSS drops dramatically to 16 — the natural two-group structure is captured. Beyond \(k=2\), further splits only subdivide already-tight groups, producing much smaller WCSS reductions — this is the "elbow."

from sklearn.cluster import KMeans
import numpy as np
import matplotlib.pyplot as plt

X = np.array([[2,2],[2,4],[2,6],[8,2],[8,4],[8,6]])

wcss = []
k_values = range(1, 6)
for k in k_values:
    model = KMeans(n_clusters=k, random_state=42, n_init=10)
    model.fit(X)
    wcss.append(model.inertia_)

plt.plot(k_values, wcss, marker="o")
plt.xlabel("k"); plt.ylabel("WCSS")
plt.show()
print(list(zip(k_values, wcss)))   # look for the "elbow" -- k=2 here

Graphical Intuition

k WCSS elbow at k=2

The curve bends sharply at k=2 — before it, each extra cluster helps a lot; after it, gains flatten out.

Practical Use Cases

  • The standard first check when \(k\) isn't known ahead of time from business context
  • Combined with silhouette score for a more rigorous, less subjective confirmation

Common Mistakes

  • Treating the elbow method as fully automated — the "elbow" is often visually judged, and real data frequently doesn't show as clean a bend as this textbook example.
  • Not testing a wide enough range of \(k\) values to actually see where the curve flattens.

Interview Relevance

Q: "Why can't you just pick the k that minimizes WCSS?" WCSS decreases monotonically as k increases, reaching exactly 0 when k equals the number of data points — minimizing it directly would always favor the maximum possible number of clusters, defeating clustering's purpose; the elbow method instead looks for the point of diminishing returns.

Practice Question

A WCSS-vs-k plot shows a very gradual, smooth decline with no obvious bend at any point. What does this suggest about the data's underlying cluster structure?

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

K-Means Elbow Method – FAQs

Quick answers about learning K-Means Elbow Method in Machine Learning.

This free note from CodingNow 2.0 explains K-Means Elbow Method in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including K-Means Elbow Method, is 100% free with no signup required.
With focused practice, most students grasp K-Means Elbow Method in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now