Bayesian K-means Clustering

Statistics
Introduced by
Kulis & Jordan (ICML 2012) formalized the Bayesian nonparametric derivation; Bishop (2006) established the variational Bayesian EM framework for Gaussian mixture models as a probabilistic foundation
Year
2006–2012
Type
Probabilistic clustering / Bayesian nonparametric
Family
Multivariate analysis

What does it do?

Bayesian K-means extends classical K-means by placing a Gaussian prior over each cluster centroid, so that centroid estimates combine the data with prior beliefs.

Cluster memberships become posterior probabilities rather than hard labels, and the model supports comparison across candidate numbers of clusters. The prior matters most when a cluster contains few points.

The intuition behind the method

Classical K-means assigns each data point to exactly one cluster and finds centroids by minimising squared distances, but it does not report how certain those assignments are. Bayesian K-means keeps the same alternating logic within a probability model: each centroid has a prior distribution, and each point's assignment is a probability (a responsibility) rather than a hard label. Centroid beliefs are updated from the weighted data in each cluster, and the prior pulls those estimates toward its mean when a cluster has few members. Dirichlet process K-means (DP-means) is a related but different method. It is a hard-assignment algorithm obtained as the small-variance limit of a Dirichlet process Gaussian mixture, and it lets the number of clusters grow with the data. It does not provide the soft memberships of the model described here.

History

Kulis and Jordan (2012) revisited k-means through Bayesian nonparametrics and derived new algorithms. One of these is DP-means, a hard-assignment nonparametric clustering algorithm that links Bayesian mixture modelling with k-means-type clustering. Bishop (2006) is a textbook that covers Gaussian mixture models fitted by EM (Chapter 9) and approximate Bayesian inference (Chapter 10), which provide the probabilistic background for the model on this page. The Bayesian K-means model described here, with a Gaussian prior on centroids, is distinct from DP-means.

When to use it

Choose Bayesian K-means when you need probabilistic memberships, for example to see which points lie between clusters, and when you want a formal criterion for the number of clusters rather than an ad hoc rule. It is a reasonable choice when some clusters are expected to be small, because the prior keeps their centroids from fitting a few points too closely. It assumes continuous multivariate data with roughly Gaussian clusters. Do not use it when hard, easily communicated labels are the main goal and the extra modelling is not justified, or when the dataset is so large that iterative Bayesian updates are impractical compared with standard K-means.

Limitations and considerations

  • Computationally more demanding than classical K-means; variational or MCMC inference adds substantial overhead on large datasets.
  • Choice of prior (m0, S0) influences results, particularly when clusters are small or data are sparse — prior sensitivity analysis is needed.
  • Assumes Gaussian cluster shapes; non-spherical or non-Gaussian clusters are poorly captured without model extensions.
  • Results can be difficult to communicate to non-statistical audiences compared to the intuitive hard-assignment output of standard K-means.

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

Strengths

  • Gives soft, probabilistic cluster assignments (responsibilities) rather than hard labels, so the uncertainty of each membership is visible.
  • The prior shrinks centroid estimates for small clusters toward the prior mean, which reduces the tendency of those centroids to fit a handful of points.
  • Marginal likelihood provides a model-comparison criterion for choosing the number of clusters K.
  • A Dirichlet process formulation removes the need to fix K in advance and lets the number of clusters be inferred from the data. Its hard-assignment algorithm, DP-means, is a limiting case without soft memberships.

Applications

  • Clustering continuous multivariate measurements in which some groups are small, where prior regularisation keeps centroid estimates from being driven by a few points.
  • Identifying points that are ambiguous between clusters, using soft responsibilities instead of forced hard labels.
  • Exploratory analysis where the number of groups is unknown and model comparison across candidate K values is preferred to an ad hoc stopping rule.
  • Flagging points with low responsibility under every cluster as candidates for review, with the caveat that these scores depend on the Gaussian cluster assumption.

How it works

How it works

1

Each cluster centroid is given a Gaussian prior with mean m0 and covariance S0. These quantities encode beliefs about where centroids lie before the data are seen. For a cluster with few members, the prior limits how far the centroid estimate can move toward a small local sample.

Formula
p(\mathbf{\mu}_k) = \mathcal{N}(\mathbf{m}_0, \mathbf{S}_0)
2

Each observation xi is modelled as drawn from the Gaussian distribution of its assigned cluster k, with mean μk and a precision matrix Λ. Λ is a single precision matrix shared by all clusters and is treated as known in the closed-form update, so it carries no cluster index k. Estimating Λ would require an additional prior and is not part of this formulation. The likelihood links the centroid estimates to the data.

Formula
p(\mathbf{x}_i \mid z_i = k, \mathbf{\mu}_k) = \mathcal{N}(\mathbf{x}_i; \mathbf{\mu}_k, \mathbf{\Lambda}^{-1})
3

The responsibility rik, the posterior probability that point i belongs to cluster k, is proportional to the mixing weight πk multiplied by the likelihood of the point under cluster k. In a fully Bayesian treatment, centroid uncertainty is integrated out, which yields a predictive distribution over assignments.

Formula
r_{ik} \propto \pi_k \, \mathcal{N}(\mathbf{x}_i; \mathbf{\mu}_k, \mathbf{\Lambda}^{-1})
4

The centroid posterior is updated in closed form from the prior and the responsibility-weighted data for each cluster. The posterior mean is a weighted average of the prior mean m0 and the responsibility-weighted data mean, and the weight on the data grows with the effective cluster size Nk. Large clusters are therefore driven mainly by the data, while small clusters stay closer to the prior.

Formula
\mathbf{\mu}_k^{\text{new}} = \frac{\mathbf{S}_0^{-1}\mathbf{m}_0 + \sum_i r_{ik}\mathbf{x}_i}{\mathbf{S}_0^{-1} + N_k}
5

Model selection, that is, choosing K, is handled either by comparing model evidence (marginal likelihood) across candidate values of K, or by using a Dirichlet process prior that leaves K unbounded and infers its effective value from the data. Variational Bayes or MCMC sampling can be used when exact posterior computation is intractable.

Common pitfalls

  • Using a vague, uninformative prior and then treating the Bayesian output as inherently superior to classical K-means — the benefit of Bayesian regularisation only materialises with a reasonably informative or calibrated prior.
  • Neglecting convergence diagnostics when using MCMC; chains may mix poorly in high dimensions, producing misleading posterior summaries.
  • Conflating soft assignments (responsibilities) with meaningful cluster probabilities when the Gaussian model assumptions are violated.
  • Fixing K before running the model despite using a Bayesian framework — the model-selection advantage is only realised by comparing evidence across K values or using a nonparametric prior.

Frequently asked questions

How is Bayesian K-means different from a Gaussian mixture model?

Gaussian mixture models (GMM) also give soft memberships and are the probabilistic generalisation of K-means. The model described on this page places a prior over the centroids and uses a single precision matrix Λ shared by all clusters and treated as known, so it is closer to a mixture with a common, fixed covariance structure than to a full GMM in which each component has its own covariance. Maximum-likelihood EM for GMMs includes no prior. Bayesian GMMs, by contrast, place priors on component parameters (Bishop 2006, Chapter 10), and they are closely related to the model on this page.

What is DP-means and how does it relate to Bayesian K-means?

DP-means (Dirichlet Process K-means) is a hard-assignment clustering algorithm derived by Kulis and Jordan (2012) as the small-variance limit of a Dirichlet process Gaussian mixture model. It determines the number of clusters automatically by creating a new cluster when a point lies farther than a threshold distance from all existing centroids. Because it assigns each point to a single cluster, it does not produce the soft responsibilities of the model described on this page, although it keeps the simple structure of K-means with a Bayesian nonparametric justification.

How do I choose the prior in Bayesian K-means?

The prior mean m0 and covariance S0 are chosen by the analyst from plausible centroid locations and scales, based on domain knowledge. Sensitivity analysis, in which the model is re-run with different priors, shows whether the conclusions depend on that choice.

When should I prefer standard K-means over its Bayesian version?

Standard K-means is preferable when hard assignments must be easy to communicate, when the dataset is very large and computational cost matters, or when the number of clusters is known and the Gaussian assumptions are clearly reasonable. The Bayesian version adds value mainly through probabilistic memberships, prior regularisation of centroids, and formal comparison across values of K.

Can Bayesian K-means handle non-Gaussian clusters?

The model described here assumes Gaussian clusters. Non-Gaussian or strongly non-spherical clusters require model extensions, such as Bayesian mixtures with non-Gaussian components. If the true clusters are highly non-spherical, the results of this model can be misleading regardless of the prior.

Related methods

Sources

  1. Kulis, B. & Jordan, M. I. (2012). Revisiting k-means: New algorithms via Bayesian nonparametrics. In Proceedings of the 29th International Conference on Machine Learning (ICML), Edinburgh, Scotland, pp. 513–520.

    Open publication reference
  2. Bishop, C. M. (2006). Pattern Recognition and Machine Learning. Springer. Chapter 9 (Mixture models and EM) and Chapter 10 (Approximate Inference).

    ISBN: 978-0387310732