For GDA with binary y∈{0,1}, y∼Bernoulli(ϕ) and x∣y=k∼N(μk,Σ), how do you derive the maximum likelihood estimates of ϕ, μ0, μ1 and Σ from n labelled points?

Supervised learning, Gaussian discriminant analysis
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can write the joint log-likelihood and differentiate with respect to each parameter, including the covariance.

Key idea

The joint likelihood factorises, so each parameter is a class count or class average: ϕ^=n1/n, μ^k= class mean, Σ^=1n∑i(xi−μ^yi)(xi−μ^yi)⊤.

Steps

  1. Because GDA is generative, we maximise the joint log-likelihood ℓ=∑i[ln⁡P(yi)+ln⁡p(xi∣yi)]. The two parts have separate parameters.
  2. For ϕ: ℓϕ=∑i[yiln⁡ϕ+(1−yi)ln⁡(1−ϕ)]. Setting the derivative to zero: n1ϕ−n01−ϕ=0, so ϕ^=n1n, the fraction of class 1.
  3. For μk: ℓ=−12∑i(xi−μyi)⊤Σ−1(xi−μyi)+const. The gradient with respect to μk is Σ−1∑i:yi=k(xi−μk). Setting it to zero gives μ^k=1nk∑i:yi=kxi.
  4. For Σ: ℓ=n2ln⁡∣Σ−1∣−12∑i(xi−μyi)⊤Σ−1(xi−μyi)+const. Write Λ=Σ−1 and use ∂ln⁡∣Λ∣∂Λ=Λ−1 and ∂ a⊤Λa∂Λ=aa⊤.
  5. The derivative is n2Σ−12∑i(xi−μyi)(xi−μyi)⊤=0, so Σ^=1n∑i(xi−μ^yi)(xi−μ^yi)⊤.
  6. This is the pooled within-class covariance: the weighted average of the two class covariances, n0nΣ^0+n1nΣ^1, with the class means (not the overall mean) subtracted.

Common mistakes

How long your answer should be

One page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: Multiple discriminant analysis (multi-class Fisher LDA) solves SBv=λSWv. For C=3 classes in d=100 dimensions with n=60 training points, how many useful discriminant directions are there, and what goes wrong with SW? How can you fix it?
Next in Supervised learning: Show that a naive Bayes classifier with two classes and binary features is a linear classifier in x, and give its weights. For P(y=1)=0.5, P(x1=1∣y=1)=0.8, P(x1=1∣y=0)=0.2, P(x2=1∣y=1)=0.6, P(x2=1∣y=0)=0.3, find the log-odds for x=(1,0) and x=(1,1). What goes wrong if feature 2 is copied twice?