K-Means ClusteringIntro
k-Means Inertia
~8 mincode completion
Implement kmeans_inertia(X, centroids, labels) returning J as a float.
Where this shows up
~8 min
••
1 employer weight this skill
1 health and bio company. Top match scores 87.
Python
import numpy as np
def kmeans_inertia(X, centroids, labels):
"""
The k-means objective for a given assignment.
Args:
X: array of shape (n, d)
centroids: array of shape (k, d)
labels: integer array of shape (n,), the cluster of each point
Returns:
float: sum of squared distances from each point to its assigned centroid
"""
# YOUR CODE HERE
pass