Laplace smoothing
2.4.10· AI-ML › SVM, Naive Bayes & Probabilistic Models
WHY chahiye yeh humein?
Naive Bayes classify karta hai is tarah:
Ek conditional ka Maximum Likelihood estimate sirf ek count ratio hota hai:
WHAT hai Laplace smoothing?
HOW derive karen isse (Bayesian first principles)
outcomes ke counts ko Multinomial se model karo jisme unknown probabilities hain. Ek Dirichlet prior rakho jisme saare parameters ke barabar hain:
Counts observe karo (total ). Dirichlet Multinomial ka conjugate hai, isliye posterior bhi Dirichlet hai:
ka posterior mean (natural point estimate) hai:

Worked Example 1 — Spam word
Vocabulary size : {buy, free, meeting, project, lunch}. Spam class mein humne total words dekhe, counts hain: buy=4, free=3, meeting=1, project=0, lunch=0.
"project" ke liye raw MLE:
Yeh step kyun? Failure dikhata hai: "project" wala koi bhi email spam-score 0 paayega, doosre words se regardless.
Add-one ():
Yeh step kyun? Denominator hai . Ab impossible sirf unlikely ho jaata hai.
"buy" check karo:
Yeh step kyun? Smoothing confident estimates ko thoda uniform () ki taraf shrink karta hai, jo desirable regularization hai.
Sum check: ✓ Yeh step kyun? Confirm karta hai ki yeh valid distribution hai — use karne ka yahi point hai.
Worked Example 2 — ka effect
Wohi "project" count = 0, , :
| (barely smoothed) | |
| (almost uniform) |
Yeh step kyun? Jaise , har estimate (max smoothing, data ignore). Jaise , raw MLE milta hai. Toh ek bias–variance knob hai, jo cross-validation se tune hota hai.
Worked Example 3 — Test word jo kabhi dekha hi nahi
Maan lo ek test email mein "hello" hai, jo kisi bhi class ki vocabulary mein nahi hai. Handle karne ka tarika: ya toh unknown tokens drop karo, ya ek <UNK> slot reserve karo taaki usse count kare. Agar count 0 ke saath include kiya:
Yeh step kyun? Consistency: tumhe wahi (UNK slot sameto) dono classes ke numerator normalization aur har class mein use karna chahiye, warna alag classes ke probabilities alag scales par hoti hain.
Recall Feynman: ek 12-saal ke bachche ko samjhao
Socho tum guess kar rahe ho ki kaunse cereal box mein toy aata hai. Tumne 8 boxes khole, kuch toys dekhe lekin kabhi robot nahi dekha. Kya iska matlab robot impossible hai? Nahi! Bas tumne itne boxes nahi khole. Toh shuru mein, tum pretend karo ki tumhe pehle se har ek toy ek baar mil chuki hai. Ab kuch bhi "impossible" nahi, bas rare hai. Yahi Laplace smoothing hai — har cheez ki ek imaginary sighting add karo taaki koi surprise tumhara poora guess na todo.
Forecast-then-Verify
Aage padhne se pehle predict karo: agar main vocabulary double kar dun lekin counts same rakhun, toh zero-count word ki smoothed probability upar jaayegi ya neeche? → Neeche, kyunki denominator badh jaata hai jabki numerator sama rehta hai — zyada possible outcomes matlab har unseen ek individually zyada rare. (VERIFY block mein verified.)
Flashcards
Unsmoothed Naive Bayes unseen feature values par kyun fail karta hai?
Laplace-smoothed conditional probability likho.
Denominator mein (na ki ) kyun add karte hain?
Laplace smoothing mein kya hai?
Add-one smoothing kya hai?
Lidstone smoothing kya hai?
Kaun sa Bayesian model exactly Laplace smoothing deta hai?
Jaise kya hota hai?
Jaise kya hota hai?
ko tune kaise karte hain?
Connections
- Naive Bayes Classifier — smoothing iske conditional probability estimates ke andar rehti hai.
- Maximum Likelihood Estimation — unsmoothed baseline ().
- Dirichlet Distribution & Conjugate Priors — add- ka Bayesian origin.
- Bias-Variance Tradeoff — isko control karta hai.
- Bag of Words / Text Classification — jahan = vocabulary size.
- Log probabilities — numerical underflow se bachne ke liye smoothing ke saath use hota hai.