How do you derive the E-step and M-step of the EM algorithm for a Gaussian mixture model with K components?

Probabilistic models, EM algorithm
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can introduce latent assignments, compute responsibilities with Bayes' rule, and maximise the expected complete-data log-likelihood in closed form.

Key idea

With latent zi∈{1,…,K}, the E-step computes responsibilities γik=πk N(xi∣μk,Σk)∑jπj N(xi∣μj,Σj), and the M-step maximises ∑i∑kγik[log⁡πk+log⁡N(xi∣μk,Σk)], giving weighted means, weighted covariances and mixing proportions πk=Nk/n.

Steps

  1. Model: p(x)=∑kπk N(x∣μk,Σk), where πk are mixing weights that sum to 1 and N(x∣μk,Σk) is a Gaussian with mean μk and covariance Σk. The log-likelihood ∑ilog⁡∑kπk N(xi∣μk,Σk) has a log of a sum, so setting its gradient to zero has no closed-form solution.
  2. Introduce zi with p(zi=k)=πk and p(xi∣zi=k)=N(xi∣μk,Σk). The complete-data log-likelihood ∑i∑k1[zi=k](log⁡πk+log⁡N(xi∣μk,Σk)) has no log of a sum.
  3. E-step: replace 1[zi=k] by its posterior expectation γik=p(zi=k∣xi,θold), computed with Bayes' rule as in the key idea. It is the "soft" share of point i that belongs to cluster k. Let Nk=∑iγik, the effective number of points in cluster k.
  4. M-step for the means: setting ∂Q/∂μk=∑iγikΣk−1(xi−μk)=0 gives μk=1Nk∑iγikxi. Similarly Σk=1Nk∑iγik(xi−μk)(xi−μk)⊤.
  5. M-step for the weights: maximise ∑kNklog⁡πk subject to ∑kπk=1 with a Lagrange multiplier. This gives Nk/πk=λ; summing over k gives λ=n, so πk=Nk/n.
  6. Iterate until the log-likelihood stops improving. Note that with shared covariance σ2I and σ→0, the responsibilities become hard assignments and EM reduces to k-means.

Common mistakes

How long your answer should be

One page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Probabilistic models: How is the forward recursion for a hidden Markov model derived? For the HMM with states Rainy (R) and Sunny (S), π=(0.6,0.4), transitions P(R→R)=0.7, P(R→S)=0.3, P(S→R)=0.4, P(S→S)=0.6, and emissions P(walk∣R)=0.1, P(shop∣R)=0.4, P(walk∣S)=0.6, P(shop∣S)=0.3, what is P(walk,shop)?
Next in Probabilistic models: Why does an iteration of the EM algorithm never decrease the observed-data log-likelihood?