ML.INSPECT.INERTIA¶
Returns the inertia (sum of squared distances of samples to their closest cluster center) of a fitted K-Means model.
Syntax¶
Arguments¶
| Name | Type | Default | Description |
|---|---|---|---|
| model | object | Fitted K-Means model (created by ML.CLUSTERING.KMEANS and trained with ML.FIT). |
Returns¶
The inertia score as a single number — lower means tighter clusters.
When to use¶
Use ML.INSPECT.INERTIA to read the sum of squared distances of every
sample to its closest cluster center after fitting a K-Means model. It's the
quantity K-Means itself minimises, so lower is better — but only relative to
the number of clusters, since adding more clusters can only ever shrink the
inertia.
The most common reason to pull inertia into a cell is the elbow method for
choosing n_clusters: fit K-Means for several values of k, plot the inertia
against k, and pick the value where the curve visibly flattens.
Examples¶
Fit K-Means with three clusters on the data in A2:E100, then read the
inertia of the fitted model:
=ML.CLUSTERING.KMEANS(3, "k-means++", "auto", 300, 0.0001, 0)
=ML.FIT(H1, A2:E100)
=ML.INSPECT.INERTIA(H2)
Build an elbow table by laying out a column of k values, fitting K-Means at
each, and pulling the inertia next to it — a quick scatter chart over the
result reveals the elbow:
A2: 2 B2: =ML.CLUSTERING.KMEANS(A2, "k-means++", "auto", 300, 0.0001, 0)
C2: =ML.FIT(B2, $A$25:$E$125)
D2: =ML.INSPECT.INERTIA(C2)
A3: 3 ...
Remarks¶
- The model passed in must be a K-Means model (created by
ML.CLUSTERING.KMEANS) that has been fitted withML.FIT. Passing any other estimator type, or a K-Means model that hasn't been fitted yet, raises an error. - Inertia decreases monotonically as
n_clustersgrows, so the absolute value is rarely useful on its own — always compare across multiple values ofk. - Pre-scale your features with
ML.PREPROCESSING.STANDARD_SCALERbefore fitting K-Means. Inertia is computed in raw feature space, so unequal magnitudes will dominate the metric. - For a complementary cluster-quality score that doesn't depend on
kin the same way, seeML.EVAL.CLUSTERING.SILHOUETTE_SCORE.
Compatible with¶
| Constructor | Description |
|---|---|
| ML.CLUSTERING.KMEANS | Creates a K-Means model to group similar data. |