Skip to content

Clustering, density estimation, and anomaly detection · Mixture and density models · UCL039 · Model

Gaussian mixture model (GMM)

Model continuous data as a weighted combination of Gaussian populations, providing soft assignments, density estimates, and a model-based clustering interpretation.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.gmm. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Model continuous data as a weighted combination of Gaussian populations, providing soft assignments, density estimates, and a model-based clustering interpretation.

Question / hypotheses

Which probability model adequately explains the reference distribution and its latent heterogeneity? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

A finite weighted collection of Gaussian densities fitted by alternating responsibility and parameter updates.

Assumptions

Components are Gaussian, but the overall distribution need not be. Unconstrained likelihood can diverge when a covariance collapses around a point; regularization and adequate effective sample sizes matter. A statistical component need not be a meaningful real-world class.

Formula / computational definition

p(x)=∑k=1KπkN(x;μk,Σk)p(x)=\sum_{k=1}^K\pi_k\mathcal N(x;\mu_k,\Sigma_k), with nonnegative weights summing to one. EM alternates responsibilities rik∝πkN(xi;μk,Σk)r_{ik}\propto\pi_k\mathcal N(x_i;\mu_k,\Sigma_k) and weighted parameter updates. Learned parameters are weights, means, and covariance matrices.

Parameters and notation

Learned or fitted quantities: Mixture weights, means, covariances, and responsibilities. User-set hyperparameters/design choices: Choose KK, covariance structure, regularization, initialization, and convergence tolerance. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Refit likelihood or posterior parameters on the new reference population; neural fine-tuning does not apply to this classical model. Warm starts can reduce computation but should be compared with fresh initialization. Recheck predictive fit and regularization after a domain shift.

How to use and calibrate

Compare held-out log density, BIC/AIC under appropriate assumptions, posterior assignment uncertainty, and predictive checks. Check multiple starts and covariance eigenvalues. Bayesian finite mixtures add priors to these same parameters; they are an extension here rather than a second count.

Example application

Model overlapping numerical subpopulations and posterior memberships. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.

Interpretation / pitfalls

Watch out

The reported result is conditional on the representation and objective. A stable partition can reflect nuisance structure such as batch, collection site, or missingness. Confirm the interpretation in original variables and an independent sample.

Python and R code examples

Use sklearn.mixture.GaussianMixture and mclust::Mclust. Align covariance parameterizations across languages; their default model searches differ. Predictive log likelihood and clustering quality answer related but distinct questions.

Component: Gaussian-mixture density and posterior responsibilities. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Gaussian-mixture density and posterior responsibilities. · needs numpy

import numpy as np
x=.5; mu=np.array([0.,3.]); sd=np.array([1.,1.]); pi=np.array([.6,.4])
w=pi*np.exp(-.5*((x-mu)/sd)**2)/(np.sqrt(2*np.pi)*sd)
result=np.r_[w.sum(),w/w.sum()]
print(result)
R

Component demo, not a trained model — Gaussian-mixture density and posterior responsibilities.

x=.5; mu=c(0,3); sd=c(1,1); pi=c(.6,.4); w=pi*dnorm(x,mu,sd)
result=c(density=sum(w),w/sum(w))
print(result)

Sources

From the CodeSplash reference, entry UCL039.