Skip to content
mlmentorship

Gaussian mixture models

Model data as a weighted sum of K Gaussians. Soft clustering, density estimation, and the canonical EM example.

Published · 6 min read ·Role-specific ·Intermediate

Visual quick review

Visual first · depth when needed

Explain how one observation in an overlap region receives nonzero responsibility from multiple Gaussian components and therefore contributes fractionally to each component's M-step update.

Preparing the visual…

Summary

A Gaussian mixture model assumes data is generated by sampling a component from a categorical distribution with weights and then sampling :

GMMs are the canonical:

  • Soft clustering algorithm (each point has a posterior responsibility distribution over components, not a hard assignment).
  • Continuous density estimator with adjustable expressiveness via .
  • Building block for HMMs (state emissions), VAEs (mixture priors), and many speech / vision systems.
  • EM teaching example. The simplest non-trivial latent-variable model with closed-form EM updates.

The latent variable view

Define a one-hot latent with . Then . Marginalize: .

The latent is what makes GMM a soft-clustering algorithm: posterior tells you how much “responsibility” component has for .

Learning objective

See how one observation updates more than one Gaussian

An overlap point receives soft responsibility from two Gaussian components Two Gaussian density contours overlap around an observation x. Component one uses a solid contour and component two uses a dashed contour. Each component forms an unnormalized score by multiplying its prior mixture weight by its density at x. Normalizing the two scores produces posterior responsibilities r one and r two, which sum to one. The same observation then contributes weight r one to component one's effective count, mean, and covariance updates and weight r two to component two's updates. Neither responsibility is a hard zero or one assignment. ONE OBSERVATION IN AN OVERLAP REGION μ₁ component 1 · solid μ₂ component 2 · dashed observation x COMPONENT 1 SCORE s₁ = π₁ N(x; μ₁, Σ₁) prior × density at x COMPONENT 2 SCORE s₂ = π₂ N(x; μ₂, Σ₂) prior × density at x NORMALIZE ACROSS COMPONENTS r₁ = s₁/(s₁+s₂) · r₂ = s₂/(s₁+s₂) RESPONSIBILITY r₁ 0 < r₁ < 1 RESPONSIBILITY r₂ 0 < r₂ < 1 · r₁+r₂=1 x ENTERS BOTH M-STEP UPDATES component 1 with weight r₁ · component 2 with weight r₂
Read it this way: the ellipses show where each component assigns density, not a hard boundary. At x, multiply each density by its prior weight π, then normalize those scores into r₁ and r₂. Because both responsibilities are between zero and one, the same point contributes fractionally to both components' effective counts, means, and covariances. The construction is original and checked against Dempster, Laird, and Rubin (1977), Bishop (2006), and the scikit-learn GaussianMixture documentation.

Training: EM

Initialize (k-means++ for means, identity for covariances). Iterate until log-likelihood stabilizes.

E-step: for each point and component :

M-step:

Covariance structure

Trade expressiveness for parameter count by restricting :

FormParameters per componentUse case
FullDefault; expressive
DiagonalHigh-d data, fewer parameters
Spherical 1Approximates k-means with soft assignments
Tied (shared across components) onceUsed in linear discriminant analysis

Choosing

Same problem as k-means. Standard approaches:

  • Information criteria: BIC () or AIC (). Pick minimizing.
  • Cross-validation log-likelihood.
  • Dirichlet process mixture (infinite GMM): non-parametric Bayesian alternative that lets grow with data.

GMM vs. k-means

Propertyk-meansGMM
Cluster shapeSpherical, equal radiusArbitrary ellipsoid (full )
AssignmentHard (0/1)Soft (probability over components)
Parameters centroids centroids + covariances + weights
Compute per iter for full
Soft probabilitiesNoYes
Density estimationNo (Voronoi cells)Yes

GMM is k-means generalized: k-means = GMM with shared identity covariance, equal weights, and hard assignments.

Use cases

  • Soft clustering with ellipsoidal clusters.
  • Density estimation for low-d continuous data.
  • Anomaly detection: low-likelihood points are anomalies.
  • Speaker diarization: GMMs over MFCC features (legacy speech).
  • Background subtraction in video: GMM per pixel.
  • Mixture of experts gating in neural networks (related but distinct).

For high-dimensional data: pure GMMs struggle (covariance estimation requires parameters per component). Use diagonal covariance, dimensionality reduction, or normalizing-flow alternatives.

Common pitfalls

  • Covariance singularities. A component centered on a single point has and log-likelihood diverges. Add jitter .
  • Initialization. Random init often gives degenerate clusters; use k-means++ centroids as initial means.
  • Reading mixture weights as cluster sizes. is the prior; effective cluster size is .
  • Comparing GMM and k-means on cluster counts. GMM components and k-means clusters are not directly comparable; soft mass distributes differently.