Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
from sklearn.cluster import KMeans
X = np.array([[0], [4], [10], [14]])
model = KMeans(n_clusters=2, n_init=10, random_state=0).fit(X)
print(round(model.inertia_, 1))16.0
- Expecting
8.0, the sum of plain distances: inertia squares each distance to the centroid, so the four distances of2give4 * 2 ** 2 = 16.0. - Expecting
4.0, an average per point:inertia_is a sum over all points, not a mean, so it grows with the number of points.
- What would
inertia_be withn_clusters=4on the same four points? - Why can inertia not be compared between two datasets of different sizes?