K-Means Inertia and the Elbow

easy
Unit 5 · Clustering & Decision Trees0/3 to milestone

Inertia is the sum of squared distances from each point to its assigned centroid.

Implement:

  • inertia(X, labels, centroids)
  • elbow_k(inertias): given inertias for k = 1, 2, ..., K, return the k at the "elbow": the point with the largest second difference I[k-1] - 2 I[k] + I[k+1] (only interior points qualify, so 2 <= k <= K-1; ties go to the smaller k)
#clustering#k-means#model-selection2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
K-Means Inertia and the Elbow · TechGradify