CAB212 · Unit 3: Classification
Naive Bayes classifier
8 practice questions
Key points
- Posterior proportional to likelihood x prior
- Assumes conditional independence
- Laplace smoothing avoids zero probabilities
- Good, fast text baseline
Naive Bayes applies Bayes' theorem: P(C|x) = P(x|C) P(C) / P(x), and assumes features are conditionally independent given the class, so P(x|C) = product of P(x_i|C). It predicts the class with the largest posterior; P(x) can be ignored when comparing classes.
Variants: Gaussian (continuous features), Multinomial (word counts), Bernoulli (binary features).
Laplace smoothing adds 1 to counts so an unseen feature value does not give probability zero: P = (count + 1) / (total + number of categories).
Worked example: P(spam)=0.4, P(word|spam)=0.5, P(word|ham)=0.1. Posterior spam = 0.4*0.5 / (0.4*0.5 + 0.6*0.1) = 0.2/0.26 = 0.769.
Strengths: fast, works with little data, good for text. Weakness: independence assumption is rarely true, so probabilities are poorly calibrated even when classification is good.
Exam pitfall: "naive" refers to the independence assumption, not to poor accuracy.
Try two questions
Which Naive Bayes variant suits continuous features assumed normal within each class?
- Complement Naive Bayes only
- Gaussian Naive Bayes
- Multinomial Naive Bayes
- Bernoulli Naive Bayes
Show the answer
B. Gaussian NB fits a normal per feature and class.
Which Naive Bayes variant suits word-count features?
- Gaussian, for continuous measurements
- K-means with Euclidean centroids
- Linear, with a weight vector
- Multinomial
Show the answer
D. Multinomial models count data.