Clusters as Gaussians
A Gaussian mixture models data as coming from groups, each a Gaussian blob with its own centre , shape and share of the points. Fitting one finds the blobs; it also gives every point a soft membership in each group, which is what makes it more than a clustering.
This page fits three Gaussians to scikit-learn's wine data: 178 wines from three Italian cultivars, 13 chemical measurements each, standardized and projected on their first two principal components (36 % and 19 % of the variance). The fit never sees the cultivars; the true cultivar colouring is only there to compare against afterwards.
Why it needs EM
The best parameters maximize the log-likelihood . The sum inside the logarithm has no closed-form maximum. But if we knew which component produced each point, each component could be fitted on its own points with a mean and a covariance. Expectation–maximization alternates between guessing those assignments softly and refitting on the guess.
The E-step and the M-step
The E-step computes each point's responsibilities, the posterior probability that each component produced it, by Bayes' rule:
The E-step panel does this for the wine you click, in logs, because early on the densities are far too small for ordinary numbers. The map colours every wine by its responsibilities, so a wine between two ellipses shows a mixed colour.
The M-step refits each component to all the points at once, each weighted by its responsibility: , , and , plus a tiny on the diagonal that scikit-learn adds so no covariance collapses. The panel computes these from the current responsibilities next to scikit-learn's recorded values for the next iteration; they agree.
Neither step can lower the likelihood. The E-step makes a lower bound on the log-likelihood touch it at the current parameters, and the M-step maximizes that bound, so every curve in the Forty starts chart only rises.
Where you start decides where you end
Rising is not the same as reaching the top. The likelihood of a mixture has several local maxima, and EM climbs whichever one it starts on. The page runs forty starts with scikit-learn's random_from_data initialization: each component begins as a point-sized Gaussian on one randomly chosen wine, so the first E-step hands every wine to the nearest of the three, like one round of k-means.
The forty starts end at six different points. 22 reach the best, a log-likelihood of −612.625, whose clusters match the cultivars with an adjusted Rand index of 0.896. 13 end at −612.632, almost as likely but a different split of the wines, matching the cultivars only at 0.662: the likelihood can barely tell two quite different answers apart. Five starts get stuck lower, between −622.4 and −635.3 (Rand index 0.34 to 0.46). In each of them one component has settled on a small group of 3 to 20 wines, and the other two must stretch over all three cultivars. The worst button shows seed 18: after 127 iterations its third component holds 3 wines, and one ellipse covers the first cultivar together with most of the second. scikit-learn's default start, k-means, lands on the best answer in 30 iterations, which is why it is the default; running several starts and keeping the most likely is the usual remedy.
Where it came from
Dempster, Laird and Rubin gave EM its name and general form in 1977, for any model with missing data; the cluster assignments here are the missing data. Wu proved when it converges, and Neal and Hinton showed that both steps maximize the same function, which explains why partial and incremental versions also work. k-means is the limit of EM with equal, shrinking spherical covariances and hard assignments; the IVF-PQ tab in Retrieval uses its codebooks.
Papers
- Maximum Likelihood from Incomplete Data via the EM Algorithm Names and generalizes EM, with Gaussian mixtures among its examples, and proves the likelihood never decreases.
- On the Convergence Properties of the EM Algorithm When EM converges, and that it converges to a stationary point, which need not be the global maximum.
- A View of the EM Algorithm that Justifies Incremental, Sparse, and other Variants Both steps as coordinate ascent on one free-energy function: the lower bound the E-step tightens and the M-step raises.
- Local Maxima in the Likelihood of Gaussian Mixture Models: Structural Results and Algorithmic Consequences Bad local maxima exist even for well-separated mixtures, and random starts reach them with real probability, as five of forty do here.