All problems
Inertia List
Problem
Compute k-means inertia for several candidate centroid sets. For each centroid list, sum over points the squared Euclidean distance to the nearest centroid.
Return one inertia per centroid set in order; empty points yields zeros.
Hint
Inertia is the total squared distance from each point to its closest centroid.
Test cases
case 1
in: [[[0,0],[2,0],[10,10]],[[[0,0]],[[0,0],[10,10]],[[0,0],[2,0],[10,10]]]]
expected: [204,4,0]
case 2
in: [[[1],[5]],[[[1]],[[1],[5]]]]
expected: [16,0]
case 3
in: [[],[[[0,0]]]]
expected: [0]
Starter codePython
def inertia_list(points, centroids_per_k):
# Your code here
pass3 test cases · run your code against them in the editor