← chapter

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

The math

E-step — responsibility of component kk for point ii:

γik=πkN(xiμk,σk2)jπjN(xiμj,σj2)\gamma_{ik} = \frac{\pi_k\, \mathcal{N}(x_i \mid \mu_k, \sigma_k^2)}{\sum_j \pi_j\, \mathcal{N}(x_i \mid \mu_j, \sigma_j^2)}

M-step — responsibility-weighted updates:

πk=1Niγik,μk=iγikxiiγik\pi_k = \frac{1}{N}\sum_i \gamma_{ik}, \quad \mu_k = \frac{\sum_i \gamma_{ik} x_i}{\sum_i \gamma_{ik}}

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.

Takeaways