A naive Bayes classifier maps inputs to discrete class labels by assuming that features are conditionally independent given the class. This assumption factorizes the class-conditional density into one-dimensional feature densities, even when the assumption is not literally true. section 5.5 section 5.8
For Bernoulli naive Bayes, each xᵢⱼ records whether word j is absent or present in document i. Parameters θⱼc describe word probabilities for class c, while π represents the class-label prior. With dictionary size D and C classes, the parameter count is O(DC). section 5.5
Training and inference follow a compact probabilistic derivation:
- Factor the document likelihood across features using conditional independence. section 5.5
- Maximize the log likelihood for the model parameters. section 5.5
- Enforce that class probabilities sum to one with a Lagrangian, then set parameter gradients to zero. section 5.5
Document classification
Represent documents as binary word-presence vectors and classify them with Bernoulli naive Bayes. A from-scratch implementation defines class and dictionary dimensions, initializes π and θ, and fits them from training documents and labels. section 5.5
Figure 5.12 Naive Bayes probabilistic graphical model
Use the probabilistic graphical model to inspect the class label, observed word variables, and conditional-independence structure. section 5.5
Figure 5.13 Naive Bayes algorithm pseudo-code
Use the pseudocode to trace the training procedure before implementing the classifier. section 5.5




