ML02.6 · Naive Bayes and generative classifiers
ML02.6 L2 · Intermediate 4 lessons · about 100 min Live · in review
Part of ML02 Supervised Learning: Trees, Ensembles and Kernels in the Machine Learning track.
There are two ways to build a classifier: learn the border between the classes, or learn what each class looks like and let Bayes’ rule decide. These four lessons take the second road. They prove that the largest posterior gives the lowest possible error rate, make the naive assumption that turns an impossible density into one small model per feature, build Bernoulli, multinomial and Gaussian naive Bayes from counts and means, show that naive Bayes is a linear classifier on text, and measure what the assumption costs when features carry the same evidence twice.
What you need first. Logistic regression and the log loss (ML01.6), Bayes’ rule (M06.4), conditional independence (M06.3), densities and the normal curve (M06.6), and maximum likelihood (S02.3).
Lessons
Generative and discriminative classifiers ML02.6.1 25 min
A classifier can learn the border between classes directly, or learn what each class looks like and let Bayes’ rule do the rest. See both routes on one feature, prove that the largest posterior gives the lowest error rate, and find the best threshold by hand.
The naive assumption and Bernoulli naive Bayes ML02.6.2 25 min
A full model of which of 500 words an email contains needs more numbers than there are atoms in the universe. Assume the words are independent within each class and it needs one number per word. Build Bernoulli naive Bayes on the inbox, in logs, with add-one smoothing.
Multinomial naive Bayes for text ML02.6.3 25 min
Treat a message as a bag of word counts and each class as a die with one face per word. Estimate the faces by smoothed counting, work a tiny corpus by hand, and discover that naive Bayes is a linear classifier whose weights are log ratios of word probabilities.
Gaussian naive Bayes and when the assumption hurts ML02.6.4 25 min
For measurements, give every feature of every class its own bell curve. Fit Gaussian naive Bayes to the twelve points and to iris, see why its boundary curves, then watch correlated features count the same evidence twice and push its probabilities to 0 and 1.
The interactive
ML02.6-X1 · Two-class Gaussian explorer. Drag two bell curves, change their spreads and slide the prior. The weighted curves, the shaded Bayes error, the posterior and the thresholds update together, and a button duplicates the feature to show naive Bayes counting the same evidence twice. It lives in Gaussian naive Bayes and when the assumption hurts.