X-means: Extending K-means with Efficient Estimation of the Number of Clusters

Dan PellegAndrew Moore

article2000ICML2,908 citations

Proposes the X-means algorithm, an extension of K-means that automatically determines the number of clusters using local Bayesian Information Criterion tests accelerated by multiresolution kd-trees to achieve superior clustering quality and major speedups on large datasets.

Listen

Clustering large datasets requires choosing in advance how many groups to form, a step that standard K-means leaves to the user and that becomes impractical for big or high-volume data. The X-means work set out to remove that requirement by building an algorithm that both finds a suitable number of clusters and places them efficiently while still producing results at least as good as conventional K-means.

The authors start from an already-accelerated version of K-means that stores summary statistics in a kd-tree and uses geometric tests to avoid checking every point against every center. They then add a structure-improvement step that repeatedly splits each current center into two local candidates, runs a short two-center refinement inside the parent region only, and accepts or rejects the split according to the Bayesian Information Criterion. The process repeats, increasing the number of centers only where the data support it, until an upper limit supplied by the user is reached. Experiments used both synthetic Gaussian mixtures with known true cluster counts and real astronomical catalogs containing hundreds of thousands of galaxies.

X-means recovered cluster counts within roughly 15 percent of the true value on synthetic data and produced lower distortion and higher BIC scores than K-means given the correct count in advance. On the same hardware it ran about twice as fast as repeated accelerated K-means trials over a comparable range of K values; on a 330,000-point galaxy set the speed-up reached roughly thirty-fold relative to naïve repeated K-means. In the Sloan Digital Sky Survey sample the method returned an average cluster size of about 470 objects with far smaller run-to-run variation than the baseline approach.

These results matter because they let analysts apply clustering to millions of records without exhaustive trial-and-error searches for K and without sacrificing statistical quality. The method therefore supports timely exploration of large scientific or operational datasets where the right number of groups is not known beforehand.

The authors note that the same local-decision framework can be extended to other model-selection criteria such as AIC and to mixture-model fitting beyond hard K-means assignments; both directions are already under study. The main limitations are that the current implementation assumes spherical clusters of equal variance and has been demonstrated only up to four dimensions, so users facing strongly non-spherical or very high-dimensional data should validate results on representative subsets before scaling.

No sufficiently relevant recommendations were found.

Cover for X-means: Extending K-means with Efficient Estimation of the Number of Clusters

Abstract

Despite its popularity for general clustering, K-means suffers three major shortcomings; it scales poorly computationally, the number of clusters K has to be supplied by the user, and the search is prone to local minima. We propose solutions for the first two problems, and a partial remedy for the third. Building on prior work for algorithmic acceleration that is not based on approximation, we introduce a new algorithm that efficiently, searches the space of cluster locations and number of clusters to optimize the Bayesian Information Criterion (BIC) or the Akaike Information Criterion (AIC) measure. The innovations include two new ways of exploiting cached sufficient statistics and a new very efficient test that in one K-means sweep selects the most promising subset of classes for refinement. This gives rise to a fast, statistically founded algorithm that outputs both the number of classes and their parameters. Experiments show this technique reveals the true number of classes in the underlying distribution, and that it is much faster than repeatedly using accelerated K-means for different values of K.

Table of Contents

  • 1. Introduction
  • 2. Definitions
  • 3. Estimation of KK
  • 3.1 Model Searching
  • 3.2 BIC Scoring
  • 3.3 Acceleration
  • 4. Experimental Results
  • 5. Conclusion
  • Acknowledgements
  • References

Knowls

  1. Knowl 1 — X-means Clustering Algorithm

    algorithm

    The X-means algorithm automatically estimates the number of clusters KK within a user-specified range [Kmin⁡,Kmax⁡][K_{\min}, K_{\max}] while simultaneously estimating cluster parameters. It iteratively alternates between optimizing centroid locations for a fixed KK and testing whether individual clusters should be split into two.

    Input: Dataset D⊂RMD \subset \mathbb{R}^M, minimum cluster count Kmin⁡K_{\min}, maximum cluster count Kmax⁡K_{\max}
    Output: Best centroid configuration C∗\mathcal{C}^* and estimated number of clusters K∗K^*
    K←Kmin⁡K \leftarrow K_{\min}
    Initialize centroid set C={μ1,…,μK}\mathcal{C} = \{\mu_1, \dots, \mu_K\} randomly or via seeding
    C∗←C\mathcal{C}^* \leftarrow \mathcal{C}
    best_score←−∞\text{best\_score} \leftarrow -\infty
    while K≤Kmax⁡K \le K_{\max} do
        C←Improve-Params(C,D)\mathcal{C} \leftarrow \text{Improve-Params}(\mathcal{C}, D) // Run conventional K-means to convergence
        current_score←BIC(C,D)\text{current\_score} \leftarrow \text{BIC}(\mathcal{C}, D)
        if current_score>best_score\text{current\_score} > \text{best\_score} then
            best_score←current_score\text{best\_score} \leftarrow \text{current\_score}
            C∗←C\mathcal{C}^* \leftarrow \mathcal{C}
        end if
        Cnew←∅\mathcal{C}_{\text{new}} \leftarrow \emptyset
        for each centroid μj∈C\mu_j \in \mathcal{C} do
            {μj,1,μj,2}←Improve-Structure(μj,Dj)\{\mu_{j,1}, \mu_{j,2}\} \leftarrow \text{Improve-Structure}(\mu_j, D_j) // Local 2-means and BIC comparison
            Cnew←Cnew∪{μj,1,μj,2}\mathcal{C}_{\text{new}} \leftarrow \mathcal{C}_{\text{new}} \cup \{\mu_{j,1}, \mu_{j,2}\} if split accepted else Cnew∪{μj}\mathcal{C}_{\text{new}} \cup \{\mu_j\}
        end for
        if ∣Cnew∣==∣C∣|\mathcal{C}_{\text{new}}| == |\mathcal{C}| or ∣Cnew∣>Kmax⁡|\mathcal{C}_{\text{new}}| > K_{\max} then
            break
        end if
        C←Cnew\mathcal{C} \leftarrow \mathcal{C}_{\text{new}}
        K←∣C∣K \leftarrow |\mathcal{C}|
    end while
    return C∗\mathcal{C}^*
  2. Knowl 2 — Local Centroid Splitting and Model Selection

    model/method

    In the Improve-Structure step of X-means, each parent centroid μj\mu_j currently owning a subset of points Dj⊆DD_j \subseteq D is tested for splitting into two children μj,1\mu_{j,1} and μj,2\mu_{j,2}:

    1. Two candidate child centroids are instantiated by displacing μj\mu_j along a randomly oriented vector by a distance proportional to the geometric size of the region DjD_j in opposite directions.
    2. A local 2-means clustering algorithm is executed exclusively on the subset DjD_j until the positions of μj,1\mu_{j,1} and μj,2\mu_{j,2} converge.
    3. A local Bayesian Information Criterion (BIC) test is performed comparing the single parent model (k=1k=1) against the two-children model (k=2k=2) on the subset DjD_j.
    4. If BIC(k=2)>BIC(k=1)\text{BIC}(k=2) > \text{BIC}(k=1), the split is accepted and the parent centroid is replaced by the two child centroids. Otherwise, the split is rejected and the parent centroid is retained.

    This localized decision structure explores up to 2K2^K possible split configurations in parallel per global iteration while isolating local cluster structure decisions.

  3. Knowl 3 — Bayesian Information Criterion (BIC) for Spherical Gaussian Clustering

    equation

    Under the assumption that data points are generated by KK identical spherical Gaussian distributions with isotropic variance σ2\sigma^2, the Bayesian Information Criterion (BIC) for model MjM_j on dataset DD with ∣D∣=R|D| = R in MM dimensions is:

    BIC(Mj)=l^j(D)−pj2log⁡R\text{BIC}(M_j) = \hat{l}_j(D) - \frac{p_j}{2} \log R

    where l^j(D)\hat{l}_j(D) is the log-likelihood of the data at the maximum likelihood estimate, and pjp_j is the number of free parameters. The maximum likelihood estimate of the isotropic variance σ^2\hat{\sigma}^2 over the entire dataset partitioned into KK clusters with centroids μ(i)\mu_{(i)} assigned to point xix_i is:

    σ^2=1R−K∑i=1R∥xi−μ(i)∥2\hat{\sigma}^2 = \frac{1}{R - K} \sum_{i=1}^{R} \|x_i - \mu_{(i)}\|^2

    The conditional log-likelihood evaluated on the subset DnD_n containing Rn=∣Dn∣R_n = |D_n| points belonging to centroid nn is:

    l^(Dn)=−Rn2log⁡(2π)−Rn⋅M2log⁡(σ^2)−Rn−K2+Rnlog⁡Rn−Rnlog⁡R\hat{l}(D_n) = -\frac{R_n}{2} \log(2\pi) - \frac{R_n \cdot M}{2} \log(\hat{\sigma}^2) - \frac{R_n - K}{2} + R_n \log R_n - R_n \log R

    The total number of free parameters pjp_j for KK clusters in MM dimensions consists of (K−1)(K - 1) independent cluster probabilities, M⋅KM \cdot K centroid coordinates, and 11 shared variance parameter:

    pj=(K−1)+M⋅K+1=K(M+1)p_j = (K - 1) + M \cdot K + 1 = K(M + 1)

  4. Knowl 4 — KD-Tree Acceleration and Geometric Blacklisting

    model/method

    X-means accelerates both global KK-means and local split iterations by indexing the entire dataset in a multiresolution kdkd-tree without introducing numerical approximations.

    Each node in the kdkd-tree represents a subset of points and stores its spatial bounding box, total point count RvR_v, and the coordinate sum vector ∑x∈vx\sum_{x \in v} x. When assigning points to centroids, a recursive traversal maintains a candidate list of centroids for each node. Centroids that are geometrically proven to be farther from every point in the node's bounding box than another candidate centroid are pruned ("blacklisted").

    If the candidate list for a kdkd-tree node reduces to a single dominant centroid, the traversal terminates at that node, and the centroid's sufficient statistics (point count and center-of-mass sum) are directly incremented by RvR_v and ∑x∈vx\sum_{x \in v} x. For local split operations (Improve-Structure), once a kdkd-tree node is determined to be owned entirely by a single parent centroid, recursive assignment continues restricted solely to the two child candidates of that parent.

  5. Knowl 5 — State Caching and Invariant Preservation Across Structure Refinements

    model/method

    To eliminate redundant computations during iterative model searches, X-means employs two state-caching mechanisms:

    1. Write-Once Centroid Tracking and Node Contribution Caching: Centroid coordinates are stored in a write-once structure with unique integer identifiers. When a kdkd-tree node's list of competing centroids does not change across iterations and those centroids have not moved, the cached contribution to their sufficient statistics is reused without re-traversing descendant nodes. Centroid comparison is performed in O(1)O(1) time using a hash-table lookup of identifiers.
    2. Zombie Centroid Caching: When a parent centroid's children are rejected during local testing, they are preserved in a "zombie" state. If the parent's location remains unchanged in subsequent iterations, the cached children and their local 2-means results are instantly recalled rather than recomputed from scratch.
  6. Knowl 6 — Distortion and Cluster Estimation Accuracy on Synthetic Data

    empirical result

    On synthetic datasets generated from mixtures of 250 spherical Gaussians in 3 dimensions with sample sizes ranging from 75,000 to 125,000 points, X-means achieved lower average squared distortion per point (averaging approximately 0.000670.00067 to 0.000720.00072) than standard KK-means initialized with the true number of clusters K=250K = 250 (which averaged 0.000780.00078 to 0.000830.00083). This occurs because X-means incrementally places new centroids in regions where existing clusters fail BIC tests rather than relying on a single global random initialization.

    When identifying the true number of classes (K=100K=100) on 2-D datasets across sizes from 5,000 to 40,000 points, X-means consistently estimated between 88 and 92 clusters (within 15% of the true count). X-means tended to slightly underestimate KK and remained insensitive to dataset size RR, whereas grid-search KK-means using global BIC over-estimated KK (outputting 100 to 106 clusters) and scaled upward as RR increased.

  7. Knowl 7 — Error in Cluster Count Estimation Across Varying True Classes

    data/table

    The following table compares the mean absolute error in the estimated number of clusters produced by grid-search KK-means (evaluating 20 equally spaced values up to 2K2K) versus X-means (searching the range [2,…,2K][2, \dots, 2K]) on 2-D synthetic datasets with sample sizes between 4,000 and 36,000 points:

    True Classes KK-means Error X-means Error
    50 3.53±0.373.53 \pm 0.37 3.00±0.893.00 \pm 0.89
    100 5.77±0.585.77 \pm 0.58 9.06±1.009.06 \pm 1.00
    150 9.65±4.289.65 \pm 4.28 21.43±2.2621.43 \pm 2.26

    The measurements show that for smaller numbers of true classes (K=50K=50), X-means achieves lower absolute error (3.003.00) than grid-search KK-means (3.533.53). For higher cluster densities (K=100K=100 and K=150K=150), X-means exhibits larger under-estimation error because randomly generated neighboring Gaussian components overlap and are statistically modeled more parsimoniously as single clusters under the BIC penalty.

  8. Knowl 8 — Computational Speedup and Scalability

    empirical result

    On synthetic datasets in 3 dimensions with 250 classes, X-means demonstrated superior computational scaling compared to iterated accelerated KK-means searching over multiple values of KK:

    • Across dataset sizes from 5,000 to 40,000 points, X-means executed in approximately half the run-time of iterated KK-means (e.g., ~190 seconds vs. ~340 seconds at 40,000 points on a 233-MHz Pentium-2 processor).
    • On a dataset containing over 330,000 data points, X-means completed in 238 seconds, whereas naive KK-means evaluating 10 candidate values of KK required 7,793 seconds, representing a 32-fold speedup.
    • The speed advantage expands as the dataset size RR grows because localized 2-means tests and kdkd-tree sufficient statistics eliminate redundant distance evaluations across distant clusters.
  9. Knowl 9 — Application of X-means to Galaxy Redshift Clustering

    empirical result

    X-means was evaluated on observational astronomical datasets to discover characteristic galaxy cluster sizes:

    • Sloan Digital Sky Survey (SDSS): On a dataset of approximately 800,000 sky objects partitioned into 18 spatial cells, X-means searched K∈[R/1000,R/100]K \in [R/1000, R/100] and estimated an average cluster size of 473±25.5473 \pm 25.5 objects, compared to 572±40.8572 \pm 40.8 objects for iterated KK-means. X-means clustered the full 800,000-point dataset into 4,000 resulting centroids in 4.5 hours on a 600-MHz DEC Alpha, whereas iterated KK-means exceeded double that run-time before hitting hard resource limits.
    • Las Campanas Redshift Survey: When clustering galaxy coordinates with KK constrained between 50 and 500, X-means found solutions with BIC scores comparable to an optimized standard KK-means search over 10 candidate KK values while completing the search 8 times faster.
  10. Knowl 10 — Theoretical and Computational Limitations of X-means

    limitation

    The X-means algorithm has two primary structural limitations:

    1. Distributional Assumptions: The splitting score relies on identical spherical Gaussian distributions with isotropic covariance Σ=diag(σ2)\Sigma = \text{diag}(\sigma^2) and hard cluster assignments. If the true data clusters are non-spherical, elongated, or have heterogeneous variances, the BIC test can over-split natural clusters or select an inaccurate model structure.
    2. Dimensionality Bottleneck of Spatial Trees: The exact geometric blacklisting acceleration depends on multiresolution kdkd-trees. While exact and effective in low dimensions (empirically demonstrated up to 4 dimensions, with practical viability up to roughly 7 dimensions), kdkd-tree spatial partitioning suffers from the curse of dimensionality, losing pruning efficiency in high-dimensional feature spaces.

Coverage note — No substantial contributed material was omitted. All core components of X-means—including the model search algorithm, local splitting procedure, BIC equation formulation, kd-tree acceleration, caching optimizations, synthetic and astronomical empirical results, and stated limitations—have been extracted.

References

  1. 1.Bishop, C. M. (1995). Neural networks for pattern recognition. Oxford: Clarendon Press.
  2. 2.Bradley, P. S., & Fayyad, U. M. (1998). Refining initial points for K-Means clustering. Proceedings of the Fifteenth International Conference on Machine Learning (pp. 91–99). Morgan Kaufmann, San Francisco, CA.
  3. 3.Deng, K., & Moore, A. W. (1995). Multiresolution instance-based learning. Proceedings of the Twelfth International Joint Conference on Artificial Intelligence (pp. 1233–1239). San Francisco: Morgan Kaufmann.
  4. 4.Duda, R. O., & Hart, P. E. (1973). Pattern Classification and Scene Analysis. John Wiley & Sons.
  5. 5.Ester, M., Kriegel, H.-P., & Xu, X. (1995). A database interface for clustering in large spatial databases. Proceedings of First International Conference on Knowledge Discovery and Data Mining. Menlo Park: AAAI.
  6. 6.Kass, R., & Wasserman, L. (1995). A reference Bayesian test for nested hypotheses and its relationship to the Schwarz criterion. Journal of the American Statistical Association, 90, 773–795.
  7. 7.Las Campanas Redshift Survey (1998). http://manaslu.astro.utoronto.ca/~lin/lcrs.html.
  8. 8.Meila, M. (1999). Efficient Tree Learning. Doctoral dissertation, Massachusetts Institute of Technology, Department of Computer Science, Cambridge, MA.
  9. 9.Moore, A. W. (1999). Very fast mixture-model-based clustering using multiresolution kd-trees. Advances in Neural Information Processing Systems 10 (pp. 543–549). Morgan Kaufmann.
  10. 10.Ng, R. T., & Han, J. (1994). Efficient and effective clustering methods for spatial data mining. Proceedings of VLDB.
  11. 11.Pelleg, D., & Moore, A. (2000). Accelerating exact k-means with geometric reasoning (Technical Report CMU-CS-00-105). Carnegie Mellon University, Pittsburgh, PA. Also available from http://www.cs.cmu.edu/~dpelleg/.
  12. 12.The Sloan Digital Sky Survey (1998). www.sdss.org.
  13. 13.Wasserman, L., & Moore, A. Density Estimation with Accelerated, Exact, Mixture Models. In press.
  14. 14.Zhang, T., Ramakrishnan, R., & Livny, M. (1995). BIRCH: An efficient data clustering method for very large databases., Proceedings of ACM SIGMOD (pp. 103–114).

Citation

MLA
Pelleg, D., and A. Moore. “X-means: Extending K-means with Efficient Estimation of the Number of Clusters”. International Conference on Machine Learning, 2000, pp. 727–34, http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.3377.
APA
Pelleg, D., & Moore, A. (2000). X-means: Extending K-means with Efficient Estimation of the Number of Clusters. International Conference on Machine Learning, 727–734. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.3377
Chicago
Pelleg, D., and A. Moore. 2000. “X-means: Extending K-means with Efficient Estimation of the Number of Clusters”. International Conference on Machine Learning, 727–34. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.3377.
Harvard
Pelleg, D. and Moore, A. (2000) “X-means: Extending K-means with Efficient Estimation of the Number of Clusters”, International Conference on Machine Learning, pp. 727–734. Available at: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.3377.
Vancouver
1. Pelleg D, Moore A (2000) X-means: Extending K-means with Efficient Estimation of the Number of Clusters. International Conference on Machine Learning 727–734

BibTeX

@article{pelleg2000means,
  title = {X-means: Extending K-means with Efficient Estimation of the Number of Clusters},
  author = {Pelleg, Dan and Moore, Andrew},
  year = {2000},
  journal = {International Conference on Machine Learning},
  pages = {727-734},
  url = {http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.3377}
}
Metadata:DOI registry

Access the Paper

This paper is available from its original source. Click below to access the PDF.

Open PDF

License: Authors