NelworksNelworks

ML & AI / Season 1 / EP06

Naive Bayes, Independent Assumptions on Correlated Features

Shez

Kurumi! I just built the ultimate spam filter!

Kurumi

(Leaning against a sorting bin) Really? It looks like you're just throwing envelopes at the wall.

Shez

No! It's **Naive Bayes**. The classic!

Shez

I trained it on 50,000 emails. It uses TF-IDF vectors!

Kurumi

Shez. Why is this in the Inbox?

Shez

W-Well... "Bank" is a safe word. "Account" is a safe word. "Your" is neutral.

Shez

The math said $P(Safe) > P(Spam)$!

Kurumi

"Free Money." "Click Here."

Kurumi

Your model can't hear the chorus. It only hears solo artists.

Kurumi

This is how Naive Bayes sees an email. A **Bag of Words**.

Kurumi

The order doesn't matter. The structure doesn't matter.

Shez

But that's the assumption! Conditional Independence! It simplifies the computation!

Kurumi

You simplified computation after lobotomizing the context.

Kurumi

In the real world, if you see "Nigerian," the probability of seeing "Prince" next to it skyrockets. They are a **Gang**.

Shez

A gang?

Kurumi

They are correlated features. They move together.

Kurumi

But your "Naive" model assumes they are total strangers who just happened to walk into the room at the same time.

Kurumi

You are multiplying their probabilities separately.

Kurumi

Let's say "Prince" appears in fairy tales (Safe). Let's say "Nigerian" appears in geography emails (Safe).

Kurumi

Your model calculates: Safe $\times$ Safe = Very Safe.

Kurumi

But "Nigerian Prince" is 100% Spam. Your model missed the **Interaction**.

Shez

Okay, so it misses some phrases. But TF-IDF fixes that, right? It weights the important words!

Kurumi

TF-IDF just makes rare words louder. It doesn't make them friends.

Kurumi

TF-IDF makes "Microbiology" screams louder than "The." But if I say "Bad Microbiology," the model still calculates "Bad" and "Microbiology" separately.

Kurumi

Look what we have here? Seems like we have a case of **Bayesian Poisoning**.

Shez

Bayesian Poisoning?

Kurumi

You fool. This is how spammers outsmart you. They stuff the email with "Good Words."

Kurumi

"Love," "Miss," "Family," "Dinner."

Kurumi

Since Naive Bayes just sums the log-probabilities (or multiplies raw probabilities), enough feathers will outweigh the lead.

Kurumi

Because the model assumes "Love" and "Friend" are independent evidence, it counts them as *separate* proof of innocence.

Kurumi

In reality, "Love" and "Friend" are redundant. You are **Double Counting** the fluff.

Shez

So the independence assumption creates... overconfidence?

Kurumi

Massive overconfidence. The probabilities are usually pushed to 0.999 or 0.001. It has no nuance.

Shez

What happened?!

Kurumi

A new word. A word your training set has never seen.

Kurumi

If the probability is zero, and you multiply...

Shez

The whole equation becomes zero.

Kurumi

You must pretend you've seen every word at least once. This prevents the "Zero Frequency" nuke.

Shez

Okay, smoothing added. But how do I fix the "Gang" problem? How do I catch "Nigerian Prince"?

Kurumi

You stop using a model that treats words like lonely islands.

Kurumi

Trees.

Kurumi

A Decision Tree splits the universe.

Kurumi

"IF contains 'Nigerian' AND contains 'Prince' THEN Spam."

Kurumi

Trees capture **Non-Linear Interactions**. They capture the dependency.

Shez

So I should just trash Naive Bayes?

Kurumi

Not necessarily.

Kurumi

Naive Bayes is fast. It's $O(N)$. It requires almost no RAM.

Kurumi

If you are filtering millions of messages per second for simple sentiment (Positive/Negative), it's fine.

Kurumi

But for adversarial attacks? For complex fraud where context is king? Then you need something like Transformers or BERT.

Shez

I'm switching to BERT!

Kurumi

Yeah about that....

Shez

Ha! Take that, Nigerian Prince!

Kurumi

BERT is computationally more expensive, but it looks like it paid off this time.

Kurumi

Just remember, no compute is free. You are always trading accuracy for cost and latency.