2.4.10 · HinglishSVM, Naive Bayes & Probabilistic Models

Laplace smoothing

1,466 words7 min readRead in English

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:

Figure — Laplace smoothing

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?
Conditional probability 0 ho jaati hai, aur kyunki NB conditionals multiply karta hai, ek 0 poori class posterior ko 0 bana deta hai.
Laplace-smoothed conditional probability likho.
.
Denominator mein (na ki ) kyun add karte hain?
Smoothed distribution ko normalized rakhne ke liye — outcomes par sum exactly 1 aata hai.
Laplace smoothing mein kya hai?
Feature ki possible values ki sankhya (jaise text ke liye vocabulary size).
Add-one smoothing kya hai?
ke saath Laplace smoothing.
Lidstone smoothing kya hai?
General ke saath Laplace smoothing.
Kaun sa Bayesian model exactly Laplace smoothing deta hai?
Multinomial likelihood with symmetric Dirichlet() prior; smoothed estimate posterior mean hai.
Jaise kya hota hai?
Har estimate uniform ki taraf jaata hai (maximum smoothing, data ignore ho jaata hai).
Jaise kya hota hai?
Raw Maximum Likelihood count ratio milta hai (koi smoothing nahi).
ko tune kaise karte hain?
Cross-validation se; yeh ek bias–variance regularization knob hai.

Connections

Concept Map

uses

can produce

due to product

fixed by

defined as

alpha K guarantees

prior

conjugate to

gives

point estimate

equals

Naive Bayes multiplies P xi given C

MLE count ratio estimate

Unseen outcome gives probability 0

One zero annihilates class score

Laplace add-alpha smoothing

Add pseudocount alpha and alpha K

Ensures probabilities sum to 1

Dirichlet prior Dir alpha

Multinomial counts model

Posterior Dir c plus alpha

Posterior mean estimate