Each 8 × 8 digit is binarised, and the naive Bayes classifier assumes the 64 pixels are independent given the digit (9.46). Fitting it is just counting: θdc is the fraction of class-c training images with pixel d on (9.53), or its Laplace-smoothed version (9.58). The top row draws the ten fitted pixel-probability maps. Change the smoothing, the size of the training set, or hide pixels at test time: a generative model can simply drop the likelihood terms of the missing pixels (9.65), while a classifier that fills them with zeros pays for it.
The 1797 digits of scikit-learn (8 × 8 pixels, values 0 to 16) are shuffled once; a pixel is “on” if its value exceeds 8. The first 1000 images can be used for training and the last 797 are always the test set. The hidden pixels are the first k of a fixed random order of the 64 pixels. With α = 0 a pixel never seen on in a class gets probability about 10−12, so one unusual pixel can veto a class.
code/ch09_linear_discriminant_analysis.py (nb_bernoulli_fit, nb_bernoulli_logjoint).