Inertia

Machine Learning
Introduced by
Stuart Lloyd, James MacQueen
Year
1967
Type
Clustering quality metric
Family
Cluster Cohesion Measure

What does it do?

Inertia, also called within-cluster sum of squares (WCSS), measures how tightly the points of a clustering lie around their cluster centroids.

It is the sum of squared Euclidean distances from each point to the centroid of its assigned cluster, so lower values indicate more compact clusters. It is the objective that k-means clustering minimises, which is where it is most often encountered.

The intuition behind the method

Inertia adds up, over all points, the squared distance from each point to the centroid of its cluster. Compact clusters give small totals and spread-out clusters give large ones. Because the value uses only distances to centroids within each cluster, it says nothing about how far apart the clusters are. A key limitation follows from the formula: the optimal value cannot increase when more clusters are allowed, and with k equal to the number of points every point is its own centroid, so inertia is zero. Inertia therefore describes the fit of a given clustering and needs a separate rule, such as the Elbow Method, to choose k.

History

In this entry, the inertia criterion is the objective of k-means clustering, which is attributed to MacQueen (1967). The MacQueen reference could not be matched in the bibliographic database, so this attribution is not yet confirmed and should be checked against the original proceedings before it is relied on. The page also cites Lloyd (1982), a paper on least-squares quantization whose optimisation criterion is the minimum average quantisation noise power. That paper is cited here for quantisation theory and does not by itself establish the k-means or inertia attribution.

When to use it

Use inertia to judge how tightly a clustering fits its data, especially when the clustering comes from k-means or another centroid-based method that minimises the same squared-error criterion. It is most informative when comparing solutions on the same dataset, with the same features, scaling and number of clusters. Do not use it alone to choose the number of clusters, because the optimal value can only fall as k grows; pair it with the Elbow Method or another selection rule. Do not use it to compare clusterings of datasets with different scales or dimensions, and do not treat it as a measure of separation between clusters. For separation, use a complementary metric from the related list, such as the silhouette score.

Limitations and considerations

  • The optimal value cannot increase as k grows, so it does not by itself indicate a good number of clusters
  • Squared Euclidean distances to centroids favour compact, roughly spherical clusters of similar size, and can misjudge elongated or unequal clusters
  • It measures only within-cluster spread; the formula contains no term for the distance between clusters
  • Outlying points contribute their squared distances to the total and can inflate inertia for the whole clustering

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Follows directly from the squared-error formula, so it needs only the cluster assignments and centroids to compute
  • Is the objective that k-means minimises, so it reflects what the algorithm optimises
  • Summarises within-cluster tightness in a single number that can be tracked across the iterations of a centroid-based method
  • Simple to explain: a lower total means the points sit closer to their centroids

Applications

  • Evaluating k-means solutions by comparing within-cluster sums of squares across runs or settings that use the same data and scaling
  • Monitoring convergence of centroid-based iterations, where the value is tracked as assignments and centroids are updated
  • Choosing k by plotting inertia against the number of clusters and applying the Elbow Method
  • Quantisation-style data compression, where the squared-error criterion is applied to minimise quantisation error (Lloyd, 1982)

How it works

How it works

1

Each point x_i is assigned to the cluster whose centroid is nearest, giving the membership sets C_r used in the final sum. The centroid μ_r of cluster r is the mean of the points in that cluster, μ_r = (1/|C_r|) Σ_{i∈C_r} x_i, so the cluster means reported by k-means software are these centroids. For a fixed partition, this mean is the value that minimises the within-cluster squared error. The same distance that the criterion sums is the one that drives this assignment.

Formula
\text{Assign each point } x_i \text{ to nearest cluster centroid } \mu_r
2

For each point, the squared Euclidean distance to its assigned centroid is computed. Squaring means that large deviations contribute disproportionately, so a few distant points can noticeably raise the total.

Formula
d_i = ||x_i - \mu_{C(i)}||^2
3

The squared distances are summed over all points, which is equivalent to summing cluster by cluster, to give one non-negative value. Smaller totals indicate tighter clusters, but the value is expressed in squared feature units and is not standardised across datasets.

Formula
\text{WCSS} = \sum_{i=1}^{n} d_i = \sum_{r=1}^{k} \sum_{i \in C_r} ||x_i - \mu_r||^2

Common pitfalls

  • Choosing k by picking the lowest inertia: the value tends to fall as k rises, so the minimum usually lies at the largest k considered, which encourages over-clustering
  • Comparing raw values across datasets or feature sets: the values are in squared feature units, so they change with scaling and dimension. Standardise the features before clustering if the values are to be compared
  • Reading a low value as proof of good clustering: compact clusters can still overlap, because the formula ignores distances between clusters
  • Treating a single k-means run as the optimum: k-means converges to a local minimum that depends on the random starts, so one run can report a higher inertia than the best run achievable. In the Statistical Learning lab example (k = 3, same data), a single start (nstart = 1) gave a total within-cluster sum of squares of 104.3319, whereas 20 starts (nstart = 20) gave 97.9793. Use multiple restarts (nstart in R, n_init in scikit-learn), report the best run, and only then compare inertia across values of k

Frequently asked questions

Why does inertia decrease as I add more clusters?

Adding clusters lets each point sit closer to a centroid, so the squared distances shrink. With k equal to the number of points, each point is its own centroid and inertia is zero. This is why inertia cannot select k on its own.

Should I normalise inertia values for comparison?

Inertia is expressed in squared feature units, so values from datasets with different scales or dimensions are not directly comparable. Standardising the features before clustering puts the inputs on a common scale. This entry does not define a normalised inertia, and definitions vary between software packages, so check the documentation you use.

How does inertia relate to the Elbow Method?

The Elbow Method plots inertia against the number of clusters and looks for the point where further reductions become small. The bend is a visual judgement rather than a computed threshold. Inertia is the metric; the Elbow Method is the rule for reading it.

Can I use inertia with non-Euclidean distances?

The inertia defined here uses squared Euclidean distance to centroids. Other distances require a different objective and a different notion of centre, so their values are not directly comparable with standard inertia.

Related methods

Sources

  1. Lloyd, S. P. (1982). Least squares quantization in PCM. IEEE Transactions on Information Theory, 28(2), 129-137.

    Open DOI reference
  2. MacQueen, J. (1967). Some methods for classification and analysis of multivariate observations. In Proceedings of the Fifth Berkeley Symposium on Mathematical Statistics and Probability (Vol. 1, pp. 281-297).

    Open publication reference