The K-modes algorithm for clustering

Miguel Á. Carreira-Perpiñán, Weiran WangarXiv 2013

TL;DR

This paper introduces K-modes, a novel clustering algorithm that finds exactly K meaningful cluster "modes" (local density maxima) rather than just centroids. It elegantly bridges the gap between K-means (which finds means) and mean-shift (which finds modes but not a fixed K), offering more interpretable and robust cluster representatives, especially for non-convex data and in the presence of outliers.

What Problem Does This Paper Address?

Traditional clustering algorithms like K-means aim to find cluster centroids, which are typically the mean of the data points within a cluster. While computationally efficient, these means can be uninterpretable or even invalid patterns, especially for non-convex clusters or when outliers are present (e.g., the mean of rotated digits might not look like any specific digit). Mean-shift, on the other hand, can find modes (local density maxima) which are more representative, but it doesn't guarantee a fixed number of clusters (K) and can be computationally expensive, particularly in high dimensions. The paper addresses the need for a clustering algorithm that can:

  1. Return exactly K clusters, as specified by the user.
  2. Find cluster representatives (centroids) that are not just means, but actual "modes" of the data distribution within each cluster, making them more interpretable and valid patterns.
  3. Be computationally efficient, especially compared to mean-shift.
  4. Be robust to outliers and misspecification of parameters like K or bandwidth.

Methods

The core innovation is the K-modes objective function, which combines the cluster assignment idea from K-means with the density maximization idea from mean-shift. Specifically, it maximizes a function that is proportional to the sum of kernel density estimates (KDEs) for each cluster, weighted by cluster assignments.

The algorithm is implemented using an iterative approach that alternates between two steps:

  1. Assignment Step: Data points are assigned to the cluster whose centroid is closest in Euclidean distance. This is similar to K-means.
  2. Mode-Finding Step: For each cluster, the centroid is updated by finding a mode of the KDE defined by the points currently assigned to that cluster. This is achieved using a mean-shift-like procedure.

A key aspect is the use of a bandwidth parameter (σ) for the KDE. The paper proposes a homotopy algorithm that starts with a very large bandwidth (effectively K-means) and gradually decreases σ. This allows the algorithm to smoothly transition from finding means to finding modes, and it helps in finding better optima than starting directly with a small bandwidth. This homotopy approach also makes the algorithm deterministic once an initial K-means optimum is found.

Datasets

The paper evaluates K-modes on several datasets:

  • Toy examples: 2D datasets with Gaussian clusters and a "two-moons" dataset to illustrate the algorithm's behavior with different cluster shapes and densities.
  • Degree Distribution of a Graph: A synthetic dataset representing the degree distribution of a graph, designed to have well-separated Gaussian and skewed power-law components, with outliers in the power-law tail.
  • Handwritten Digit Images: USPS dataset (16x16 grayscale images) for digits 0-9.
  • High-dimensional Datasets with Ground-Truth Labels:
    • COIL-20: 32x32 grayscale images of 20 objects.
  • MNIST: 28x28 grayscale handwritten digit images (sampled).
  • NIST Topic Detection and Tracking (TDT2) corpus: Documents from different semantic categories.

Key Insights and Ideas

  • Bridging K-means and Mean-Shift: K-modes elegantly unifies the strengths of K-means (fixed K, efficiency) and mean-shift (mode finding, representative centroids) by introducing a bandwidth parameter that controls the trade-off.
  • Interpretable Centroids: The algorithm's ability to find modes means centroids are more likely to be actual data patterns, making them more interpretable and useful, especially for non-convex or complex data structures.
  • Robustness to Outliers: By focusing on density maxima, K-modes is less affected by outliers than K-means, which can be pulled by extreme values.
  • Homotopy for Better Optima: The homotopy approach, starting with large bandwidths and decreasing, acts as a form of deterministic annealing, guiding the algorithm towards better local optima and providing a spectrum of cluster representations.
  • Separation of Roles: K-modes decouples the number of clusters (K) from the smoothing/density estimation parameter (bandwidth σ), unlike mean-shift where bandwidth controls both. This offers more control and flexibility.

Key Results

  • Improved Clustering Accuracy: On high-dimensional datasets with ground-truth labels (COIL-20, MNIST, TDT2), K-modes consistently outperformed K-means in terms of Adjusted Rand Index and Normalized Mutual Information, especially when using an automatically estimated bandwidth or searching a wider range of bandwidths.
  • Valid and Representative Centroids: Experiments with toy examples, degree distributions, and handwritten digits demonstrated that K-modes produces centroids that are more visually interpretable and representative of their clusters compared to K-means, which often produced blurry or invalid patterns.
  • Computational Efficiency: K-modes is computationally slightly slower than K-means but significantly faster than mean-shift, particularly in high dimensions. Its complexity is O(KND) per iteration, similar to K-means.
  • Robustness: K-modes showed better robustness to outliers and parameter misspecification (K or σ) compared to K-means and GMS in experimental evaluations.

Limitations and Future Work

  • Computational Cost: While faster than mean-shift, K-modes is still slightly slower than K-means.
  • Bandwidth Selection: Determining the optimal bandwidth (σ) can still be a challenge, although the paper suggests using standard KDE bandwidth estimation rules and exploring a range of values via the homotopy.
  • Future Work: The authors suggest exploring local bandwidths (instead of a global one), using non-Gaussian kernels (like Epanechnikov) for faster computation, and relaxing the assignment variables to be continuous for a more generalized approach. They also mention potential applications in manifold denoising and spectral clustering.

Summary updated

Abstract

Many clustering algorithms exist that estimate a cluster centroid, such as K-means, K-medoids or mean-shift, but no algorithm seems to exist that clusters data by returning exactly K meaningful modes. We propose a natural definition of a K-modes objective function by combining the notions of density and cluster assignment. The algorithm becomes K-means and K-medoids in the limit of very large and very small scales. Computationally, it is slightly slower than K-means but much faster than mean-shift or K-medoids. Unlike K-means, it is able to find centroids that are valid patterns, truly representative of a cluster, even with nonconvex clusters, and appears robust to outliers and misspecification of the scale and number of clusters.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
MNIST · N=2000, D=784, K=10K-modesAdjusted Rand Index35.5%+2.6 vs baselinesamples=2000 · clusters=10 · dimensions=784
Source quote
L188: MNIST(2000,784,10) │ 32.9 │ 35.5 (34.4) │ 1.37 │ 46.4 │ 49.2 (47.4) │ 11.7
Reported baseline / comparator measurements (3)
BenchmarkMethodMetricScoreProtocol / Evidence
COIL · N=1440, D=1024, K=20K-means baselineAdjusted Rand Index56.5%samples=1440 · clusters=20 · dimensions=1024
Source quote
L187: COIL(1440,1024,20) │ 56.5 │ 62.1 (62.1) │ 11.6 │ 76.8 │ 79.1 (79.1) │ 49.8
MNIST · N=2000, D=784, K=10K-means baselineAdjusted Rand Index32.9%samples=2000 · clusters=10 · dimensions=784
Source quote
L188: MNIST(2000,784,10) │ 32.9 │ 35.5 (34.4) │ 1.37 │ 46.4 │ 49.2 (47.4) │ 11.7
TDT2 · N=9394, D=36771, K=30K-means baselineAdjusted Rand Index55.8%samples=9394 · clusters=30 · dimensions=36771
Source quote
L189: TDT2(9394,36771,30) │ 55.8 │ 56.1 (56.1) │ N/A │ 80.0 │ 80.8 (80.7) │ N/A
BibTeX
@misc{carreiraperpinan2013k,
  author = {Miguel Á. Carreira-Perpiñán and Weiran Wang},
  title = {{The K-modes algorithm for clustering}},
  year = {2013},
  eprint = {1304.6478},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1304.6478},
}
Figure