The mixture model
A GMM with K components has a mean μₖ, covariance Σₖ and mixture weight πₖ for each component. The weights are non-negative and sum to one. Its density is:
p(x) = Σₖ πₖ 𝒩(x | μₖ, Σₖ)
The covariance controls each component’s shape and orientation. A full covariance can describe an ellipse; a spherical covariance restricts the component to a circle or sphere. The point’s responsibility rₖ is the posterior probability that component k generated it.
How EM fits the model
Expectation–Maximisation alternates two steps. In the E-step, compute each point’s responsibility under the current component parameters. In the M-step, update the means, covariances and weights using those responsibilities. Repeat until the log-likelihood stops improving meaningfully.
For two one-dimensional components, N(0, 1) with weight 0.6 and N(3, 1) with weight 0.4, the responsibility for component one is about 0.97 at x = 0.5 and 0.60 at x = 1.5. The midpoint remains uncertain rather than being forced into a hard cluster. The visualiser shows the same pattern as you change Overlap of the two groups and step through EM iterations.
EM does not promise the global best fit. It can converge to a local optimum that depends on its initial parameters, so fit from multiple starts and compare the resulting likelihood or information criterion.
Where GMMs differ from K-means
A GMM can represent components with different sizes and elliptical shapes, and it returns soft memberships. K-means uses hard assignments and prefers roughly spherical groups of similar scale. A GMM is useful when probabilistic membership or an elliptical model matches the data; K-means is simpler when compact, roughly spherical clusters are adequate.
Fit several component counts and compare criteria such as BIC or AIC, along with held-out fit and whether the resulting groups make sense for the task. These criteria balance fit against model complexity; they do not guarantee that the selected groups are meaningful.
Limits and common mistakes
- Wrong shape assumption. Gaussian components may fit ellipses, but not arbitrary structures such as crescents without using many components.
- Local optima. Use several initialisations and check stability across runs.
- Too many components. A complex mixture can fit noise as well as structure. Compare criteria and validate the use of the clusters.
- Near-singular covariance. A component can collapse around a few points. Covariance regularisation can help, but does not remove the need to inspect the fit.
For implementation details and covariance options, see scikit-learn’s Gaussian mixture documentation. Compare with K-means and hierarchical clustering when choosing a clustering method.