Module 3 — Bayes Decision Theory and Naive Bayes

Sources: Lec 7 — Bayes Decision Rule for Data Classification; Lec 8 — Naive Bayes Classifier. · Prev: Module 2 · Next: Module 4 — kNN · Index: 00_INDEX_and_Coverage

Notation

Classes ; priors , ; class-conditional density ; posterior . = standard normal CDF, = its density.

flowchart LR
    P["prior p(w)"] --> B((Bayes))
    L["likelihood p(X|w)"] --> B
    B --> Q["posterior p(w|X)"]
    Q --> D["decide argmax"]

C14. The Bayes Decision Rule

Intuition

Before seeing data you hold a prior belief about each class. After seeing you update to a posterior. The best you can do is pick the class with the highest posterior. Using only the prior (“always say the biggest class”) ignores the evidence.

Formal definition

Bayes’ theorem: Bayes decision rule: assign to if , equivalently Ties are resolved arbitrarily.

Derivation (why the denominator can be dropped)

is the same for every class, so comparing reduces to comparing numerators. The joint form: .

Special case: two Gaussian classes with common variance (1-D)

Decide iff . Using and assuming :

Key insights

  • The prior-only rule is a degenerate case ( ignored).
  • A larger prior moves the threshold toward the other class’s mean (enlarging its own region).
  • In practice, and must be estimated; optimality (C15) holds only if they are right.

Worked examples

Example 1 — Very Easy · Spam with no evidence

  • Problem: A data set has 300 spam and 700 ham mails. A new mail is classified using only the prior. Which class?
  • Asked: Prior-only decision.
  • Concept: Prior rule.
  • Approach: Priors .
  • Solution: → ham for every mail.
  • Final answer: Ham (always).

Key lesson

The prior alone never flags spam — we need the likelihood.

Example 2 — Easy · Evidence overturns the prior

  • Problem: ; at the observed : . Find the posteriors and the decision.
  • Asked: Posteriors and class.
  • Concept: Bayes’ theorem.
  • Approach: Joints, then normalise.
  • Solution: Joints: ; . . Posteriors: ; .
  • Final answer: , → .

Key lesson

A strong likelihood can overturn a larger prior.

Example 3 — Moderate · Three classes

  • Problem: Three classes with priors and likelihoods at of . Classify and give posteriors.
  • Asked: Decision and posteriors.
  • Concept: Multi-class Bayes rule.
  • Approach: Joints → normalise.
  • Solution: Joints ; sum . Posteriors .
  • Final answer: (posterior ), though it has the smallest prior.

Key lesson

Rank by the joint , not by prior or likelihood alone.

Example 4 — Hard · Same point, different priors

  • Problem: , . (a) Equal priors: threshold? (b) : threshold? (c) Classify in each case, verifying with densities.
  • Asked: Two thresholds and decisions.
  • Concept: The prior shifts the boundary.
  • Approach: Use the threshold formula; verify numerically.
  • Solution: (a) . (b) . (c) ; . Equal priors: → (consistent with ). Priors : vs → (consistent with ).
  • Final answer: Thresholds and ; goes to , then .
 density
   ▲      f1·p1 (tall, prior 0.8)        f2·p2 (short, prior 0.2)
   │        ╱‾╲                              ╱‾╲
   │      ╱     ╲                          ╱     ╲
   └────╱────────┼───────┼─────────────╱─────────────→ x
        0        1     1.69            2
              equal-prior   prior-shifted boundary

Key lesson

The same data point flips class when priors change.

Example 5 — Very Hard · Same mean, different spread

  • Problem: Equal priors, , (variance 4). Find the decision regions and the Bayes error.
  • Asked: Regions and error .
  • Concept: Unequal variances → two thresholds; .
  • Approach: Compare densities; integrate.
  • Solution: Decide iff : . So in the middle, in both tails. Error: . Under , : . Under : . .
  • Final answer: iff ; .

Key lesson

With unequal variances the Bayes boundary is not a single point; the wide class owns both tails.

Common mistakes

  • Comparing likelihoods only, forgetting priors.
  • Normalising incorrectly (posteriors must sum to 1).

Exam traps

  • Priors are estimated from the class proportions of the data.
  • The rule is ""; ties are broken arbitrarily.

Connections: C15–C18 (error, bounds, discriminants), Naive Bayes (C19), logistic regression (C27), kNN (C23).

Mastery checklist

  • Derive the posterior; drop .
  • Find the 1-D Gaussian threshold with priors.
  • Interpret a prior shift.

C15. Probability of Error and Optimality of the Bayes Rule

Intuition

A classifier’s mistakes are the regions where it picks the less likely class. The Bayes rule always picks the more likely one, so it makes the minimum possible total error.

Formal definition

For with decision regions : For the Bayes rule:

Derivation (optimality)

Every point contributes either (if placed in ) or (if placed in ). The smallest possible contribution is the minimum of the two, achieved by placing in when — exactly Bayes. Therefore for every . ∎

Closed form for equal-variance Gaussians

, , equal priors; Bayes threshold : Using , both brackets equal , so

Key insights

  • The Bayes error is a floor; no learner (kNN, SVM, NN, …) can beat it with the true distribution.
  • If the densities are estimated, optimality is no longer guaranteed.
  • Error shrinks as the means move apart relative to .

Worked examples

Example 1 — Very Easy · A discrete feature

  • Problem: A discrete feature takes values . Joint probabilities and for . Give the Bayes decision per value and the Bayes error.
  • Asked: Decisions and .
  • Concept: .
  • Approach: The larger joint wins; the smaller is the error mass.
  • Solution: : → , error . : → , error . : → , error . .
  • Final answer: ; ; .

Key lesson

Error = total mass of the losing joint at each point.

Example 2 — Easy · Closed-form Gaussian error

  • Problem: (), , equal priors. Bayes error?
  • Asked: .
  • Concept: .
  • Approach: .
  • Solution: .
  • Final answer: .

Key lesson

Only the ratio separation / matters.

Example 3 — Moderate · A wrong threshold costs error

  • Problem: Same setup as Example 2 but use the (non-optimal) threshold instead of . Compute its error and compare.
  • Asked: .
  • Concept: Optimality of Bayes.
  • Approach: .
  • Solution: . . .
  • Final answer: .

Key lesson

Moving the threshold off the Bayes point strictly increases error.

Example 4 — Hard · How far apart must the classes be?

  • Problem: For equal priors and equal variance, what separation is needed for Bayes error ? For ?
  • Asked: Two ‘s.
  • Concept: Invert .
  • Approach: .
  • Solution: . .
  • Final answer: and .

Key lesson

Pushing the error from 5 % to 1 % needs more separation ().

Example 5 — Very Hard · Bayes vs ignoring the prior vs always-majority

  • Problem: , , priors . Compute (a) the Bayes error; (b) the error of the threshold (which ignores priors); (c) the error of “always ”.
  • Asked: Three errors.
  • Concept: Bayes optimality with priors.
  • Approach: Threshold from C14 Ex. 4.
  • Solution: (a) . (b) . (c) .
  • Final answer: .

Key lesson

Bayes beats both the “ignore-prior” threshold and the trivial majority classifier.

Common mistakes

  • Writing as an integral of posteriors instead of (the lecture’s “minimum posterior” means the minimum joint).
  • Using with the wrong sign.

Exam traps

  • Optimality needs the true densities; estimated densities may not be optimal.
  • requires equal priors and equal variances.

Connections: C14, C16 (bounds), 1-NN vs Bayes (C23).

Mastery checklist

  • Prove the Bayes rule minimises .
  • Derive .
  • Compute with unequal priors.

C16. Chernoff and Bhattacharyya Error Bounds

Intuition

The Bayes error integral is usually impossible to evaluate. Replace by the smooth upper bound (a geometric-type mean), which does integrate in closed form for Gaussians.

Formal results

For and : . Hence For Gaussians : ,

  • Chernoff bound: minimise the right side over (tightest).
  • Bhattacharyya bound: the easy choice .

Derivation of

Suppose (so ). Then because and . The case is symmetric (use ). ∎

Special case: equal covariance

⇒ log-term and , maximal (so the bound is tightest) at when priors are equal.

Key insights

  • Every gives a valid bound; is a tuning knob.
  • For equal priors and equal covariances, Chernoff = Bhattacharyya.

Worked examples

Example 1 — Very Easy · The inequality

  • Problem: Check for .
  • Asked: Verify.
  • Concept: The inequality.
  • Approach: Numbers.
  • Solution: ; ✓.
  • Final answer: .

Key lesson

The geometric mean exceeds the minimum.

Example 2 — Easy · Dependence on α

  • Problem: Same with and .
  • Asked: Bound values.
  • Concept: Dependence on .
  • Approach: .
  • Solution: : . : (tight).
  • Final answer: and .

Key lesson

The bound is exact at the extreme that matches which of is smaller — but a single is used for the whole integral.

Example 3 — Moderate · Bhattacharyya vs the truth

  • Problem: , , equal priors. Bhattacharyya bound vs true error.
  • Asked: Bound.
  • Concept: with equal variances.
  • Approach: 1-D: , .
  • Solution: . Bound: . True .
  • Final answer: (true ).

Key lesson

Bounds are valid but loose.

Example 4 — Hard · Chernoff with unequal priors

  • Problem: , , priors . Minimise the bound over (Chernoff) and compare with and with the true .
  • Asked: and bounds.
  • Concept: Chernoff.
  • Approach: with .
  • Solution: . Derivative: . . At : .
  • Final answer: Chernoff (); Bhattacharyya ; true .

Key lesson

Unequal priors push the optimal away from .

Example 5 — Very Hard · Separation from covariance alone

  • Problem: , , equal priors (C14 Ex. 5; true ). Compute the Bhattacharyya bound.
  • Asked: The bound.
  • Concept: with unequal covariances.
  • Approach: Means equal ⇒ first term ; use the determinant term.
  • Solution: : . . Ratio . . Bound .
  • Final answer: (true ).

Key lesson

Differences in covariance alone contribute separation via the determinant term.

Common mistakes

  • Forgetting priors in the bound.
  • Treating the bound as the error.

Exam traps

  • Chernoff = optimise ; Bhattacharyya = fix .
  • The first term vanishes when the means coincide.

Connections: C15; mutual-information / Hellinger-type measures.

Mastery checklist

  • Prove .
  • Evaluate in 1-D.
  • Optimise .

C17. Minimum Distance Classifier

Intuition

If all classes are equally likely and spread identically round their means (a round “ball” of unit variance), the most likely class is simply the class whose mean is nearest.

Formal derivation (lecture)

, equal priors . Decide iff : (cancel constants, ) ⇒ i.e. .

Generalisation (derived)

For and unequal priors the rule is: maximise . For general common it is the Mahalanobis-distance rule .

Boundary between two means

— the perpendicular-bisector hyperplane.

Worked examples

Example 1 — Very Easy · Nearest of two means

  • Problem: , ; classify .
  • Asked: Class.
  • Concept: Nearest mean.
  • Approach: Squared distances.
  • Solution: ; .
  • Final answer: .

Key lesson

Compare squared distances; no square root needed.

Example 2 — Easy · Three classes

  • Problem: Means ; classify .
  • Asked: Class.
  • Concept: -class nearest mean.
  • Approach: Three distances.
  • Solution: ; ; .
  • Final answer: .

Key lesson

Extends directly to classes.

Example 3 — Moderate · The boundary line

  • Problem: Equation of the boundary for , , and which side is ?
  • Asked: Boundary.
  • Concept: Perpendicular bisector.
  • Approach: Equate squared distances.
  • Solution: . Test : ⇒ side is .
  • Final answer: .

Key lesson

The boundary passes through the midpoint ( ✓) and is perpendicular to .

Example 4 — Hard · With a prior

  • Problem: 1-D, , , priors . Boundary and the class of .
  • Asked: Threshold.
  • Concept: .
  • Approach: Set .
  • Solution: . At : ; . .
  • Final answer: Threshold ; (although , the midpoint).

Key lesson

Plain minimum distance is only the equal-prior special case.

Example 5 — Very Hard · When Euclid is wrong

  • Problem: Common covariance , equal priors, , , . Classify by the Euclidean minimum-distance rule and by the Bayes (Mahalanobis) rule.
  • Asked: Two decisions.
  • Concept: Minimum distance requires .
  • Approach: Compute both distances.
  • Solution: Euclid: ; ⇒ . Mahalanobis with : ; : . ⇒ .
  • Final answer: Euclidean → ; Bayes → .

Key lesson

Features with large variance (here ) must be discounted; ignoring gives the wrong answer.

Common mistakes

  • Using it with unequal priors or non-identity covariance.
  • Mixing up the minimum-distance rule with kNN (it uses means, kNN uses stored points).

Exam traps

  • Needs three assumptions: Gaussian, , equal priors.

Connections: C14, C18, k-means (C36; the assignment step = minimum distance to centroids).

Mastery checklist

  • Derive the rule from Bayes.
  • Write the boundary as a hyperplane.
  • State when Euclidean distance is wrong.

C18. Linear Discriminant Function (Gaussian, Equal Covariance)

Intuition

With two Gaussian classes sharing the same covariance, the quadratic pieces of the log-posteriors cancel, leaving a straight-line (hyperplane) boundary.

Derivation (lecture, with all steps)

, . Decide iff . Taking logs (the constant cancels): Expand: (using , both scalars, symmetric). The term appears on both sides and cancels. Rearranging, Equivalently, define decide iff .

Key insights

  • The general Bayes boundary is quadratic; it becomes linear iff .
  • The normal is generally not parallel to .
  • Priors only shift the intercept.

Worked examples

Example 1 — Very Easy · Identity covariance

  • Problem: , , equal priors. Find .
  • Asked: .
  • Concept: LDF formula.
  • Approach: .
  • Solution: ; , ; . ; boundary .
  • Final answer: ; iff .

Key lesson

With this is the perpendicular bisector (C17).

Example 2 — Easy · Diagonal covariance

  • Problem: , , , equal priors. Find and classify and .
  • Asked: and two decisions.
  • Concept: General LDF.
  • Approach: .
  • Solution: . ; . . . . .
  • Final answer: ; , .

Key lesson

Plug into ; the sign decides.

Example 3 — Moderate · A prior moves the line

  • Problem: Same as Example 2 but priors . How does the boundary move? Reclassify .
  • Asked: New intercept, decision.
  • Concept: The prior shifts .
  • Approach: Add .
  • Solution: . . .
  • Final answer: flips to .

Key lesson

The boundary translates parallel to itself.

Example 4 — Hard · Unequal variances give a parabola

  • Problem: , (variance 4), equal priors. Show the boundary is quadratic and find the decision region of .
  • Asked: Boundary roots.
  • Concept: Unequal covariance ⇒ quadratic.
  • Approach: Log-likelihood difference.
  • Solution: . Roots: , i.e. or . between the roots (e.g. ).
  • Final answer: iff ; elsewhere.

Key lesson

The coefficient is .

Example 5 — Very Hard · Correlated features tilt the line

  • Problem: , , , equal priors. (a) Find the boundary line. (b) Is it the perpendicular bisector of the means? (c) Classify with both the LDF and Euclidean nearest mean.
  • Asked: Line, comparison, two decisions.
  • Concept: differs from .
  • Approach: Invert .
  • Solution: . ⇒ . The midpoint lies on the boundary: . Boundary: . (b) The perpendicular bisector is the vertical line ; slope ⇒ not the bisector. (c) . Euclid: , .
  • Final answer: Boundary ; LDF → , Euclid → .

Key lesson

Correlated features tilt the boundary; ignoring misclassifies points near it.

Common mistakes

  • Dropping the term.
  • Sign errors in .

Exam traps

  • “Quadratic in ” for the general log-likelihood but “linear” after cancellation with equal .
  • A linear boundary needs Gaussians, two classes, same covariance.

Connections: C14, C17, logistic regression (C27: also linear), SVM (C30).

Mastery checklist

  • Derive step by step.
  • Explain why the quadratic term cancels.
  • Compute the tilt due to .

C19. Naive Bayes Classifier (Conditional Independence, MAP, Log-Space)

Intuition

Estimating directly needs exponentially many numbers. Naive Bayes assumes features are independent given the class, so the joint becomes a product of simple one-feature distributions — cheap to estimate, surprisingly effective.

flowchart TD
    W((class w)) --> X1[x₁]
    W --> X2[x₂]
    W --> X3[x₃]
    W --> Xm[x_m]

Given the class, the features do not talk to each other — only the class points to them.

Formal derivation (lecture)

(chain rule). Naive assumption: . Therefore Log version (avoids floating-point underflow): Priors: .

Key insights

  • Parameters: with binary features and classes: vs for the full joint.
  • Naive Bayes is a generative classifier (C29).
  • The ranking of classes can be right even if the probabilities are miscalibrated.

Worked examples

Example 1 — Very Easy · Estimates from counts

  • Problem: From the weather data (Module 1) find , , .
  • Asked: Four numbers.
  • Concept: Estimates from counts.
  • Approach: Count.
  • Solution: , . Sunny rows: 1,2,8 (N), 9,11 (Y) ⇒ , .
  • Final answer: .

Key lesson

All parameters are simple relative frequencies.

Example 2 — Easy · Classify a day

  • Problem: Classify with Naive Bayes.
  • Asked: Class and posterior.
  • Concept: MAP with independence.
  • Approach: Needed counts: Yes: Sunny , Cool , High , True ; No: Sunny , Cool , High , True .
  • Solution: . . Normalise: .
  • Final answer: No (posterior ).

Key lesson

The unnormalised scores suffice for the decision; normalise only if you need a probability.

Example 3 — Moderate · 200 tiny probabilities

  • Problem: A model has features; every and every ; equal priors. Why does the product fail, and how do logs fix it?
  • Asked: Failure and fix.
  • Concept: Underflow.
  • Approach: Magnitudes.
  • Solution: and . Double precision underflows below (denormals to ), so both products become ⇒ tie ⇒ arbitrary. Logs: ; .
  • Final answer: Class 2 (score ); only the log computation sees it.

Key lesson

Sum logs; never multiply many small probabilities.

Example 4 — Hard · A duplicated feature double-counts

  • Problem: Equal priors. A feature has , . The same feature accidentally appears twice (perfectly correlated). Compare the true posterior of with Naive Bayes’s.
  • Asked: Two posteriors.
  • Concept: Violated independence double-counts evidence.
  • Approach: Likelihood ratio.
  • Solution: True: . NB with two copies: .
  • Final answer: vs NB’s .

Key lesson

NB is over-confident when features are correlated, but the argmax is unchanged (still ).

Example 5 — Very Hard · Counting parameters

  • Problem: (a) Count free parameters for classes with binary features, full joint vs Naive Bayes. (b) Prove NB’s MAP rule equals the Bayes rule when the independence assumption holds.
  • Asked: Counts and proof.
  • Concept: Complexity; relation to Bayes.
  • Approach: Count; substitute.
  • Solution: (a) Full: each class has a joint over cells with free parameters ⇒ , plus prior ⇒ . NB: , plus 1 prior ⇒ . (b) The Bayes rule maximises . If features are conditionally independent, exactly; substituting gives the NB rule — identical. When independence is false, NB maximises a different (misspecified) quantity.
  • Final answer: vs parameters; NB = Bayes under conditional independence.

Key lesson

The “naive” assumption trades bias for a huge reduction in parameters and variance.

Common mistakes

  • Assuming unconditional independence (it is conditional on the class).
  • Multiplying many probabilities instead of summing logs.

Exam traps

  • Zero counts kill the product → smoothing (C21).
  • is dropped; outputs are unnormalised.

Connections: Bayes (C14), Gaussian / multinomial / Bernoulli variants (C20–C22), logistic regression (C27 / C29).

Mastery checklist

  • Derive the product rule from the chain rule.
  • Classify with logs.
  • Explain over-confidence.

C20. Gaussian Naive Bayes (Continuous Features)

Intuition

For numeric features, model each feature within each class as a bell curve, with its own mean and variance estimated from the training data.

Formal definition

with the sample mean and variance of feature among class- samples. Log form: (The maximum-likelihood variance divides by ; an unbiased estimate divides by .)

Key insights

  • If all are equal across classes, the terms cancel; the rule becomes a (weighted) nearest-mean rule.
  • Unequal variances ⇒ quadratic boundary (the wide class wins in the tails).
  • A zero variance (constant feature in a class) breaks the formula — add a small floor.

Worked examples

Example 1 — Very Easy · Peak height

  • Problem: Density of at .
  • Asked: .
  • Concept: Gaussian pdf.
  • Approach: The exponent is .
  • Solution: .
  • Final answer: .

Key lesson

Peak height .

Example 2 — Easy · Estimating parameters

  • Problem: Class A values of a feature: . Estimate (MLE).
  • Asked: Parameters.
  • Concept: Estimation.
  • Approach: Mean, mean squared deviation.
  • Solution: ; (unbiased: ).
  • Final answer: , (MLE).

Key lesson

State which variance estimator you use.

Example 3 — Moderate · One feature, equal variance

  • Problem: Class A: ; class B: ; equal priors. Classify .
  • Asked: Class.
  • Concept: 1-feature Gaussian NB.
  • Approach: Log-scores.
  • Solution: Same ⇒ compare : A: ; B: . Smaller ⇒ A.
  • Final answer: A.

Key lesson

With equal variances it is nearest-mean.

Example 4 — Hard · Two features add in log space

  • Problem: A: , . B: , . Equal priors; classify .
  • Asked: Class and log-ratio.
  • Concept: Sum of per-feature logs.
  • Approach: Constants cancel (equal variances).
  • Solution: A: . B: . Difference in favour of A.
  • Final answer: A.

Key lesson

Features contribute additively in log space.

Example 5 — Very Hard · Standard deviations, not raw distance

  • Problem: Equal priors. A: ; B: . Classify . Compare with the nearest-mean answer and explain.
  • Asked: Class and explanation.
  • Concept: Unequal-variance effect.
  • Approach: Full log-likelihoods.
  • Solution: . . B is larger. Nearest mean: vs ⇒ A.
  • Final answer: Gaussian NB: B; nearest-mean: A.

Key lesson

Distance measured in standard deviations ( vs ) matters, not raw distance.

Common mistakes

  • Forgetting the term when variances differ.
  • Zero variance → division by zero.

Exam traps

  • Gaussian NB for continuous features; multinomial / Bernoulli for discrete (counts / binary).

Connections: C14, C19, C21–C22.

Mastery checklist

  • Estimate .
  • Classify with log-scores.
  • Explain the unequal-variance effect.

C21. Multinomial Naive Bayes and Laplace (Add-One) Smoothing

Intuition

For text, a feature is a word and its value is how often it occurs. A class is summarised as a “bag” of its words; is the word’s share of that class’s word-tokens. A word never seen in a class would zero out the whole product — so we pretend we saw every word once.

Formal definition

Let = total frequency of term in all class- documents; = vocabulary size. Test document: each occurrence of a term contributes one factor.

Derivation (Laplace form)

Add to every one of the counts: numerator ; denominator . The smoothed probabilities sum to : . ∎

Key insights

  • Smoothing shrinks estimates toward the uniform value ; strongest for small classes.
  • Repeated words in a test document are counted repeatedly (multinomial) — unlike Bernoulli (C22).

Worked example corpus (used in all five)

Class (3 docs): “Chinese Beijing Chinese”, “Chinese Chinese Shanghai”, “Chinese Macao”. Class (1 doc): “Tokyo Japan Chinese”. Vocabulary Chinese, Beijing, Shanghai, Macao, Tokyo, Japan, . Test: “Chinese Chinese Chinese Tokyo Japan”.

Counts. Class : Chinese 5, Beijing 1, Shanghai 1, Macao 1, Tokyo 0, Japan 0 → total 8. Class : Chinese 1, Tokyo 1, Japan 1, others 0 → total 3. Priors .

Example 1 — Very Easy · The zero-frequency problem

  • Problem: Raw ; what happens to a test document containing Tokyo?
  • Asked: Value and consequence.
  • Concept: Zero-frequency problem.
  • Approach: .
  • Solution: . Any product containing it is .
  • Final answer: ; class would be impossible for that document.

Key lesson

One unseen word vetoes the class.

Example 2 — Easy · Smoothed estimates

  • Problem: Smoothed , , , .
  • Asked: Four numbers.
  • Concept: Laplace.
  • Approach: .
  • Solution: : total , denominator : Chinese , Tokyo . : total , denominator : Chinese , Tokyo .
  • Final answer: .

Key lesson

The smaller class gets more smoothing mass per word.

Example 3 — Moderate · Classify the test document

  • Problem: Classify the test document.
  • Asked: Class.
  • Concept: Multinomial NB.
  • Approach: Terms: Chinese ×3, Tokyo, Japan.
  • Solution: : . : . Normalised .
  • Final answer: Class .

Key lesson

“Chinese” appears three times and is very probable in , outweighing Tokyo / Japan.

Example 4 — Hard · Logs, and what happens without smoothing

  • Problem: Redo Example 3 in log space and verify; then compute what the decision would be if smoothing were not used.
  • Asked: Log scores; unsmoothed decision.
  • Concept: Logs and the zero problem.
  • Approach: .
  • Solution: : . : . ✓ ( ✓). Unsmoothed: ⇒ score; (with ): ⇒ .
  • Final answer: Smoothed → ; unsmoothed → (a spurious veto).

Key lesson

Smoothing can change the decision; unsmoothed zeros are not evidence.

Example 5 — Very Hard · Properties of Laplace smoothing

  • Problem: (a) Prove the smoothed class- probabilities sum to for terms. (b) A new class has zero training tokens. What are its probabilities? (c) How would the Example 3 posterior change if a seventh vocabulary word “Osaka” (never seen) is added so ?
  • Asked: Proof and two computations.
  • Concept: Laplace’s properties.
  • Approach: Direct.
  • Solution: (a) shown in the Derivation. (b) for every term — uniform. (c) denominator : Chinese , Tokyo , Japan ; denominator : each . Scores: : ; : . .
  • Final answer: Uniform for an empty class; with , class still wins, posterior (up from ).

Key lesson

Vocabulary size appears in the denominator — it controls how much probability mass goes to unseen words.

Common mistakes

  • Adding only to zero counts.
  • Using the number of documents instead of the vocabulary size in the denominator.
  • Forgetting that repeated words count repeatedly.

Exam traps

  • Denominator: (Lecture eq. 8.9).
  • The ratio of probabilities, not their absolute values, determines the class.

Connections: C19, C22 (Bernoulli), text classification.

Mastery checklist

  • Apply Laplace smoothing.
  • Do the full Chinese / Tokyo example.
  • Explain why zeros are dangerous.

C22. Bernoulli Naive Bayes

Intuition

Record only whether a word occurs in a document (yes / no), ignoring how often. Each word is a coin flip per document, with a class-specific head probability.

Formal definition

= fraction of class- documents containing term . With smoothing (standard form): , where = number of class- docs containing , = class- document count. A test document is scored by (the full Bernoulli model also penalises absent words). The lecture notes that Bernoulli uses only binary occurrence information and “makes mistakes on long documents”, so it is used for short texts.

Key insights

  • Multinomial counts repeats; Bernoulli does not.
  • Absent terms contribute evidence in the Bernoulli model.
  • The smoothing form is the two-outcome Laplace analogue.

Worked example corpus (same as C21)

Class docs: Chinese, Beijing, Chinese, Shanghai, Chinese, Macao; class doc: Chinese, Tokyo, Japan. Test doc (presence): Chinese, Tokyo, Japan.

Example 1 — Very Easy · Document frequencies

  • Problem: Raw and .
  • Asked: Two fractions.
  • Concept: Document-frequency estimate.
  • Approach: Docs containing the term / class docs.
  • Solution: Chinese in 3 of 3 ⇒ . Beijing in 1 of 3 ⇒ .
  • Final answer: .

Key lesson

Probabilities are per-document, not per-token.

Example 2 — Easy · Smoothed table

  • Problem: Smoothed and for all six terms.
  • Asked: Table.
  • Concept: .
  • Approach: ⇒ denominator ; ⇒ denominator .
  • Solution:
term
Chinese4/52/3
Beijing, Shanghai, Macao2/5 each1/3 each
Tokyo, Japan1/5 each2/3 each
  • Final answer: As tabulated.

Key lesson

Every term probability lies strictly in — absent-term factors never vanish.

Example 3 — Moderate · Presence-only score

  • Problem: Score the test document, using only the present terms.
  • Asked: Class (partial model).
  • Concept: Presence-only product.
  • Approach: .
  • Solution: : . : .
  • Final answer: under the presence-only version.

Key lesson

Already differs from multinomial ().

Example 4 — Hard · The full Bernoulli model

  • Problem: Score the test document with the full Bernoulli model (include absent terms Beijing, Shanghai, Macao).
  • Asked: Class and posterior.
  • Concept: Full Bernoulli.
  • Approach: Multiply for the three absent terms.
  • Solution: : . : . .
  • Final answer: Class ().

Key lesson

Absent words push toward because class “expects” Beijing / Shanghai / Macao, yet they are missing.

Example 5 — Very Hard · Why the two models disagree

  • Problem: The multinomial model (C21 Ex. 3) said ; the Bernoulli model says . Explain the discrepancy and say which is appropriate for (a) tweets, (b) 5000-word articles.
  • Asked: Reasoned comparison.
  • Concept: Counts vs presence.
  • Approach: Identify what each model uses.
  • Solution: The word “Chinese” appears 3 times in the test text. Multinomial multiplies three times, and since makes “Chinese” very likely it earns a large reward. Bernoulli sees “Chinese present” once; its decisive evidence is Tokyo / Japan present (favouring ) and the absence of Beijing / Shanghai / Macao. (a) Tweets are short: presence / absence is informative and Bernoulli works well. (b) In long documents most words occur at least once, so presence saturates; the lecture warns Bernoulli errs on long documents ⇒ multinomial.
  • Final answer: Different modelling assumptions ⇒ different predictions; Bernoulli for short texts, multinomial for long.

Key lesson

Choose the model whose generative story matches your data.

Common mistakes

  • Ignoring absent terms in the full Bernoulli model.
  • Using token counts in Bernoulli.

Exam traps

  • “Bernoulli errs on long documents” (lecture).
  • Smoothing uses in the denominator for Bernoulli (binary event), for multinomial.

Connections: C21, C19, C29.

Mastery checklist

  • Estimate document-frequency probabilities.
  • Include absent terms.
  • Contrast with the multinomial model.