The EM algorithm
k-means makes a hard choice for every point. EM refuses to guess — it hands
each point a probability of belonging to each group.
Expectation-Maximization: the load-bearing recipe for latent-variable and
missing-data problems.
The chicken and egg
- If you knew which Gaussian made each point, fitting the Gaussians is a one-liner.
- If you knew the Gaussians, guessing the labels is a one-liner.
- You know neither. So alternate:
- E-step — guess the labels softly from the current Gaussians (responsibilities).
- M-step — refit the Gaussians from those soft labels.
- Repeat until the numbers stop moving.
The math
E-step — responsibility of component k for point i:
γik=∑jπjN(xi∣μj,σj2)πkN(xi∣μk,σk2)
M-step — responsibility-weighted updates:
πk=N1i∑γik,μk=∑iγik∑iγikxi
Watch it converge
Two bells fighting over a column of numbers. Points colored by soft
responsibility; the log-likelihood climbs — and never drops.
The guarantee
EM's central promise: the log-likelihood never decreases. Not "usually" —
never, every iteration, provably.
That monotonic climb is the whole reason the method is trusted.
Scratch vs. library
Fit from a deliberately bad start; land on the same answer as
sklearn.mixture.GaussianMixture.
- Means: scratch [−1.92,3.09] vs library [−1.92,3.09]
- Log-likelihood: −681.48 for both; soft-label ARI 0.87
- True generating means were [−2.0,3.0] — recovered.
Takeaways
- EM is the go-to for latent-variable and missing-data problems.
- It only finds a local optimum — initialization matters; restart and keep the best.
- It underlies Gaussian mixtures, topic models, and HMMs.
- Next: the full 2-D story with tilted covariance ellipses — Gaussian mixture models.