- Introduced by
- Garcia-Escudero, L. A. & Gordaliza, A.
- Year
- 1999
- Type
- Robust clustering algorithm
- Family
- Machine learning
What does it do?
Robust k-means is a variant of k-means clustering that limits the influence of outliers.
At each iteration it temporarily excludes a chosen fraction α of the observations that lie farthest from their nearest center, and computes the centers only from the remaining points. Because the excluded points do not contribute to the centers, a small number of contaminated or erroneous records is less likely to pull a cluster away from the bulk of its members, as can happen with standard k-means. The same trimming algorithm is also known in the literature as trimmed k-means, a name worth searching for alongside this one. The method is designed for continuous multivariate data.
The intuition behind the method
Standard k-means computes each cluster center as the mean of all points assigned to it, so a few extreme values can move a center a long way from the main body of its cluster. Robust k-means removes the most distant observations from the center calculation, so the center reflects the bulk of the cluster rather than its outlying members. The analogy is a committee that reaches a decision while setting aside the most extreme positions. The trimming fraction α sets how many observations are set aside, so the analyst controls how much robustness is imposed. The trade-off is that the set-aside observations are not assigned to any cluster in the final solution.
History
The trimmed approach to k-means has been developed by Garcia-Escudero, Gordaliza and their co-authors. The general trimming framework for robust cluster analysis was introduced by Garcia-Escudero, Gordaliza, Matrán and Mayo-Iscar (2008) in the Annals of Statistics. It allows a proportion α of contaminating data and restricts the ratio between the largest and smallest eigenvalues of the group scatter matrices. The method also belongs to the broader robust statistics tradition associated with Huber and Hampel.
When to use it
Use Robust k-means when the data are continuous and multivariate, and you suspect that outliers, measurement errors or contaminated records would distort a standard k-means solution. It is most useful when domain knowledge gives a reasonable bound on the fraction of contaminated observations, because that bound guides the choice of α. Do not use it when k is unknown and no sensitivity analysis over k and α is planned, since the two choices interact. It is not suited to categorical or mixed-type data, for which k-modes or k-prototypes are designed. For very high-dimensional data, distances between points may become less informative, which can weaken the trimming criterion that ranks observations by distance.
Limitations and considerations
- Two tuning choices, the number of clusters k and the trimming fraction α, both affect the result and have to be selected together.
- The standard form, built on squared Euclidean distance and mean centers, favours roughly spherical clusters of comparable spread. Elongated or irregular clusters are better served by density-based or spectral methods. The general trimming approach of Garcia-Escudero et al. (2008) allows clusters with different scatters, but only under restrictions on the eigenvalue ratio of the group scatter matrices.
- Squared Euclidean distance is used both for assignment and for ranking the trimmed observations, so the choice of feature scaling directly determines which points are trimmed.
- Trimmed observations are excluded from final cluster membership, which may be a problem when those points carry substantive meaning.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The trimming fraction α gives an explicit control over how much outlying data can influence the centers.
- It keeps the basic structure of k-means, so the assignment and center-update steps remain simple to implement and interpret.
- The trimmed observations form a by-product that can be inspected as candidate outliers; they are flagged relative to the fitted clusters rather than by a formal outlier test.
- The robustness of trimmed clustering is treated formally in the general trimming framework of Garcia-Escudero et al. (2008), which handles a proportion α of contaminating data and gives conditions under which the sample solutions are consistent with the population ones.
Applications
- Segmenting customers on transactional records where a known or suspected share of entries is erroneous.
- Clustering continuous measurements, such as sensor or instrument readings, in which occasional faulty values are expected.
- Grouping survey respondents when some careless or random responses are anticipated, with the trimmed set used to flag them for review.
- Anomaly screening in which the trimmed observations are examined as candidate unusual cases, with the caveat that they are defined relative to the fitted clusters.
How it works
How it works
Choose k initial cluster centers, either at random, by k-means++ seeding, or from a user-supplied starting partition. Trimming removes points from the center update, so a poor starting configuration can be harder to recognise from the fit alone; running several restarts from different starting points is therefore advisable.
Compute the squared Euclidean distance from each observation to its nearest center. Rank all observations by this distance and temporarily exclude the fraction α of observations with the largest distances. The remaining observations are assigned to their nearest cluster. Formally, the trimmed criterion looks for a retained set containing a fraction 1 − α of the observations, together with centers, that jointly minimise the within-cluster sum of squares over that set; the alternating procedure described here approximates that joint problem.
Recompute each cluster center as the mean of the non-trimmed observations assigned to it. This is the robustness step: because the trimmed observations are excluded before the mean is calculated, they cannot shift the center.
Formula
\mu_k = \frac{1}{|C_k|} \sum_{x_i \in C_k} x_iAlternate the assign-and-trim step and the center-update step until the assignments stop changing or a convergence tolerance is reached. The set of trimmed observations can change between iterations, so convergence is usually judged from the objective, the total within-cluster sum of squares over the non-trimmed points, no longer decreasing.
After convergence, inspect the trimmed observations. If the trimmed set is small and clearly separated from the clusters, it is plausibly a set of outliers. If it is large or overlaps the clusters, reconsider α, the number of clusters k, or the choice of features. Silhouette scores can support the choice of model, but they should be computed on all observations, with each trimmed point assigned to its nearest cluster. A score computed only on the retained points excludes the least well-fitted observations and therefore overstates the separation between clusters.
Common pitfalls
- Setting α too low leaves real outliers in the centre calculation; setting it too high discards genuine cluster members and reduces the effective sample size.
- Accepting the first convergent solution from a single initialisation. Several restarts from different starting configurations are needed.
- Applying the method to categorical or binary features without a suitable numeric representation, which makes the Euclidean trimming criterion uninterpretable.
- Choosing k without examining how the solution changes with α, or the reverse.
- Not inspecting the trimmed observations, which can reveal data-quality problems worth reporting.
Frequently asked questions
How do I choose the trimming fraction α?
Start from domain knowledge about the plausible share of contaminated or erroneous observations. Then run a sensitivity analysis over a range of α values and examine how the cluster sizes and the composition of the trimmed set change. If the clusters remain stable across that range, the solution is less likely to be an artefact of one particular α.
Is Robust k-means the same as k-medoids?
No. k-medoids (PAM) uses an actual observation as each cluster's representative, whereas Robust k-means uses the mean of the retained observations and removes the most distant points before computing that mean. Both reduce the influence of outliers, but through different mechanisms.
Can I use Robust k-means for outlier detection alone?
Using the trimmed set as a flagged group is a reasonable use. However, the flags depend on the fitted clusters and on k, so dedicated methods such as Isolation Forest, or DBSCAN, which labels noise points explicitly, may be more suitable when the goal is anomaly detection and no particular number of clusters is intended.
Does Robust k-means scale to large datasets?
Each iteration requires computing the distances from all n observations to k centers, which costs O(nk), and ranking those distances to find the trimmed set, which adds a sorting cost of O(n log n). The per-iteration cost is therefore higher than that of standard k-means, and the cost of many restarts adds up on large datasets.
What if my clusters differ in spread or size?
The standard form, with equal-weight mean centers and a squared Euclidean criterion, tends to favour clusters of comparable spread, so very different densities can be split or merged incorrectly. The general trimming framework of Garcia-Escudero et al. (2008) allows clusters with different scatters, subject to restrictions on the eigenvalue ratio. For strongly varying densities, density-based or mixture-model methods such as DBSCAN or Gaussian mixture models are alternatives to consider.
Related methods
Sources
Garcia-Escudero, L. A., & Gordaliza, A. (1999). Robustness properties of k-means and trimmed k-means. Journal of the American Statistical Association, 94(447), 956–969.
Open DOI referenceGarcia-Escudero, L. A., Gordaliza, A., Matrán, C., & Mayo-Iscar, A. (2008). A general trimming approach to robust cluster analysis. Annals of Statistics, 36(3), 1324–1345.
Open DOI reference