A Gaussian naive Bayes classifier has two classes. Class A has prior 0.6, feature means (1,2) and feature variances (1,4). Class B has prior 0.4, means (3,0) and variances (1,1). Which class is the point x=(2,1) assigned to?

Supervised learning, Naive Bayes
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can multiply independent one-dimensional Gaussians (add logs) and compare class scores.

Key idea

Score each class as ln⁡P(Ck)−12∑j[ln⁡σkj2+(xj−μkj)2/σkj2] (a constant shared by both classes is dropped) and pick the larger score.

Steps

  1. Naive Bayes assumes the features are independent given the class, so a class score is its log-prior plus one log-Gaussian term per feature, using ln⁡N(x;μ,σ2)=−12ln⁡(2π)−12ln⁡σ2−(x−μ)22σ2. Both classes have two features, so the −12ln⁡(2π) parts are equal and can be dropped. Logs avoid tiny products.
  2. Class A: feature 1 (x=2, μ=1, σ2=1) gives ln⁡1+1=1. Feature 2 (x=1, μ=2, σ2=4) gives ln⁡4+14=1.386+0.25=1.636. So the score is ln⁡0.6−12(1+1.636)=−0.511−1.318=−1.829.
  3. Class B: feature 1 (x=2, μ=3, σ2=1) gives ln⁡1+1=1. Feature 2 (x=1, μ=0, σ2=1) gives ln⁡1+1=1. So the score is ln⁡0.4−12(1+1)=−0.916−1=−1.916.
  4. A has the larger score, so predict class A. The score difference is 0.087, so P(A∣x)=11+e−0.087≈0.522.
  5. It is a very close call (52% against 48%). Feature 1 treats both classes equally, feature 2 favours B by 0.318, and the prior favours A by 0.405, which is just enough to tip the result.

Common mistakes

How long your answer should be

Half a page; 4 minutes.

Read this

Previous in Supervised learning: In one dimension, class 1 has density N(0,1) and class 2 has density N(0,4) (variance 4), with equal priors. Where are the Bayes decision boundaries, and which class is chosen in each region? Why is the boundary not a single point?
Next in Supervised learning: n points are drawn uniformly in the unit ball in p dimensions. Show that the median distance from the origin to the nearest point is d=(1−(12)1/n)1/p. What is its value for n=500 with p=2 and p=10, and what does it mean for k-NN?