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?

Supervised learning, Naive Bayes
Level L3 Intermediate. Length Long. Nature Th+Mat Both.

What's being asked

Whether you can write the log-odds of naive Bayes as a sum of per-feature terms, and see how correlated features distort it.

Key idea

ln⁡P(1∣x)P(0∣x)=b+∑jwjxj with wj=ln⁡pj1(1−pj0)pj0(1−pj1), where pjk=P(xj=1∣y=k).

Steps

  1. Log-odds =ln⁡P(1)P(0)+∑jln⁡P(xj∣1)P(xj∣0), using the naive independence assumption.
  2. For a binary feature, ln⁡P(xj∣1)P(xj∣0)=xjln⁡pj1pj0+(1−xj)ln⁡1−pj11−pj0. Collect terms in xj: =xjwj+ln⁡1−pj11−pj0.
  3. So log-odds =b+∑jwjxj with wj=ln⁡pj1(1−pj0)pj0(1−pj1) and b=ln⁡P(1)P(0)+∑jln⁡1−pj11−pj0. This is linear, like logistic regression.
  4. Numbers: w1=ln⁡0.8×0.80.2×0.2=ln⁡16=2.773. w2=ln⁡0.6×0.70.3×0.4=ln⁡3.5=1.253.
  5. b=ln⁡1+ln⁡0.20.8+ln⁡0.40.7=−1.386−0.560=−1.946.
  6. x=(1,0): −1.946+2.773=0.827 (so P(y=1)≈0.695). x=(1,1): 0.827+1.253=2.080=ln⁡8. Check directly: 0.8×0.60.2×0.3=8. ✓.
  7. If feature 2 is copied, the model counts the same evidence twice: its weight effectively doubles, and for (1,1,1) the log-odds becomes 2.080+1.253=3.333 instead of 2.080. The ranking may be unchanged here, but the probability becomes over-confident, and a duplicated weak feature can outvote genuine evidence from other features.

Common mistakes

How long your answer should be

One page; 7 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: 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?
Next in Supervised learning: In least-squares linear regression, why is the fitted vector y^=Xβ^ the orthogonal projection of y onto the column space of X, and what does this say about the residuals?