Gaussian Naive Bayes
WHY does this method exist?
We want . That is hard to model directly for continuous data. Bayes' theorem lets us flip it into things we can estimate from data:
- WHAT we want: the posterior .
- WHAT we can measure: the prior (just count classes) and the likelihood (how features are distributed inside each class).
The problem: is a joint distribution over all features — hopeless to estimate with limited data. The "Naive" trick fixes this.
The Naive assumption (the 80/20 core)
WHY is this a huge win? A joint distribution over features needs exponentially many parameters. Splitting it into separate 1-D distributions needs only parameters. It is "naive" because features are rarely truly independent — but the classifier still works surprisingly well.
The Gaussian part: modelling each
We only need two numbers per feature per class: the mean and variance .
HOW do we estimate and ? (Derivation from scratch)
We use Maximum Likelihood Estimation (MLE). Take all training points in class ; their feature- values are . The log-likelihood of a Gaussian is:
Solve for — set : Why this step? The variance cancels, leaving the plain sample mean.
Solve for — set : Why this step? Multiply through by and rearrange — you get the sample variance.
So training is just: compute per-class, per-feature mean and variance. That's it.
The decision rule (put it together)
Since is the same for every class, we drop it and maximise the numerator:

Worked Example 1 — one feature, two classes
Feature = height (cm). Class A (short): . Class B (tall): . Priors equal. Classify .
- Why? Constant is identical for both classes (same ), so it cancels.
Class B (tall). Why? is closer to ; with equal and equal priors, GNB just picks the nearest mean.
Worked Example 2 — unequal variance flips intuition
Class A: . Class B: . Classify .
Class A, even though is closer to B's mean! Why this step? B is very "tight" (): a value 12 units away is extremely unlikely for B. The term and the variance in the denominator both penalise confident-but-far predictions. This is why GNB decision boundaries are curved (quadratic), not just midpoints.
Worked Example 3 — two features
Point . GNB scores . Why? The independence assumption turns the joint into a sum of per-feature log-terms — each feature votes separately.
Recall Feynman: explain to a 12-year-old
Imagine each class is a person throwing darts at a number line, aiming for their favourite spot (the mean). Some throwers are shaky (big spread) and some are super precise (small spread). A new dart lands. You guess which thrower threw it by asking: "For each thrower, how surprised would I be if THEY threw it here?" You pick the thrower who'd be least surprised — considering both how close it is to their target and how precise they usually are. The precise thrower gets little credit for far-away darts; the shaky one is forgiven. That "least surprised" rule is Gaussian Naive Bayes.
Flashcards
What core assumption makes Naive Bayes "naive"?
Why does the naive assumption help computationally?
In Gaussian NB, what distribution models each ?
What are the MLE estimates for and ?
Why do we drop in the decision rule?
Why take logs of the probabilities?
When does GNB reduce to "nearest class mean"?
Why is the GNB decision boundary generally quadratic?
What is var_smoothing for?
Full GNB decision rule (log form)?
Connections
- Bayes Theorem — the foundation GNB rewrites.
- Naive Bayes — the general family (Gaussian for continuous, Multinomial Naive Bayes for counts, Bernoulli Naive Bayes for binary).
- Maximum Likelihood Estimation — how are derived.
- Gaussian Distribution — the likelihood model.
- LDA & QDA — GNB is essentially QDA with a diagonal covariance (independent features).
- Logistic Regression — a discriminative cousin that models directly.
- Log-Sum-Exp trick — stable posterior normalisation.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Gaussian Naive Bayes ka core idea simple hai: har class ko ek bell-curve (normal distribution) maan lo. Training ke time bas har class ke andar, har feature ka mean aur variance nikaal lo — bas itna hi training hai! Phir jab naya point aata hai, to poochte ho: "Kaunsi class ki bell-curve ne is value ko sabse zyada easily produce kiya hoga?" Jis class ke liye point sabse kam surprising hai, wahi answer hai.
"Naive" isliye kehte hain kyunki hum assume karte hain ki saare features ek-dusre se independent hain (given the class). Real life mein ye galat hota hai, par phir bhi kaam karta hai — kyunki humein sirf sahi class choose karni hai, exact probability nahi chahiye. Is assumption se joint distribution tut ke chhote-chhote 1-D Gaussians ka product ban jaata hai, jo estimate karna aasan hai.
Ek important baat (Example 2 dekho): sirf "nearest mean" wala rule tabhi chalta hai jab sab classes ka variance aur prior barabar ho. Agar koi class bahut tight (chhota sigma) hai, to usse thoda door wala point bhi bahut unlikely ho jaata hai — isliye decision boundary curved (quadratic) banti hai. Aur practical tip: probabilities ko multiply mat karo, log leke add karo, warna numbers itne chhote ho jaate hain ki computer 0 bana deta hai (underflow).