What is a Gaussian mixture model?
Last updated
A Gaussian mixture model (GMM) is a probabilistic model that treats the data as generated by a weighted sum of K Gaussians: p(x) = Σₖ πₖ 𝒩(x | μₖ, Σₖ). It is usually fit with EM and gives soft cluster assignments plus a full density estimate.
Generative story:
Pick a latent component z with probability πₖ, then draw x from 𝒩(μₖ, Σₖ).
The parameters are the mixing weights π (summing to 1), the means μₖ and the covariances Σₖ.
Fitting:
Expectation-Maximization alternates two steps. The E-step computes responsibilities P(z=k | x). The M-step re-estimates π, μ and Σ.
Each iteration increases the likelihood, but EM converges only to a local optimum, so use multiple initializations (e.g.
n_init).
Compared with k-means:
GMM gives soft assignments and supports elliptical clusters of different sizes and orientations.
K-means is the limit of a GMM with equal spherical covariances shrinking to zero, which produces hard assignments.
Covariance choices: In scikit-learn,
covariance_typecan befull,tied,diagorspherical. These trade flexibility against the number of parameters.Uses and caveats:
Uses: density estimation, anomaly detection (flag low likelihood), and soft clustering.
K must be chosen (AIC/BIC or a Bayesian GMM).
Covariances can collapse onto single points, making the likelihood unbounded. Regularize with
reg_covar.It assumes roughly Gaussian-shaped clusters.