Linear Classification and Advanced Methods · Machine Learning

Naive Bayes

Watch lectures

Naive Bayes

1. Naive Assumption

Features independent given class:

p(x∣y)=p(x1∣y) times ... times p(xd∣y)p(x|y) = p(x₁|y) \text{ times } ... \text{ times } p(x_{d}|y)

Naive but works for text / high-dd small-nn. Training = count frequencies (no iteration).

2. Prediction

ypred=argmaxc[logp(y=c)+sumilogp(xi∣y=c)]y_{pred} = \text{argmax}_{c} [ log p(y=c) + \text{sum}_{i} log p(x_{i}|y=c) ]

Use logs to avoid underflow. p(xi∣y)p(x_{i}|y): Gaussian for numeric, multinomial / Bernoulli for text.

3. Smoothing (critical)

Unseen word gives zero → kills whole product. Laplace (add-1):

p(word∣c)=count+1total words in c+Vp(word|c) = \frac{\text{count} + 1}{\text{total words in } c + V}

VV = vocab size.

4. Worked (spam)

P(spam)=0.4, P(ham)=0.6
P(FREE|spam)=0.3, P(FREE|ham)=0.02
mail has FREE → spam score ∝ 0.4×0.3=0.12, ham ∝ 0.6×0.02=0.012 → spam

5. Exam Points

  • State independence + prediction rule — 5-7 marks, very frequent.
  • Laplace numerical — 5 marks, frequent.
  • Gaussian vs multinomial choice — 3 marks, frequent.
Free AppAndroid App

Coursify Android App

Generate AI courses, take quick quizzes between classes, and master complex engineering concepts on the go.

← All Machine Learning modules