Lensa ML
Lensa ML

Naive Bayes Classifier

Step 1 of 6

Class Likelihoods

How x determines P(x|class)

Observed x1.00
-4.0-1.80.52.85.00.00.10.30.40.6xdensityP(x|spam)P(x|ham)x = 1.0
P(X|SPAM)
0.2283
P(X|HAM)
0.0375
SPAM MEAN
2.0
HAM MEAN
-1.0

At x=1.0, the spam curve gives density 0.228 vs ham's 0.038. The observation is closer to spam's mean (2), so P(x|spam) > P(x|ham). These likelihoods feed into Bayes' rule in the next step.

Step 1 of 6: Class Likelihoods

How x determines P(x|class)

Observed x1.00
-4.0-1.80.52.85.00.00.10.30.40.6xdensityP(x|spam)P(x|ham)x = 1.0
P(X|SPAM)
0.2283
P(X|HAM)
0.0375
SPAM MEAN
2.0
HAM MEAN
-1.0

At x=1.0, the spam curve gives density 0.228 vs ham's 0.038. The observation is closer to spam's mean (2), so P(x|spam) > P(x|ham). These likelihoods feed into Bayes' rule in the next step.

Step 2 of 6: Bayes' Rule

Prior × likelihood ÷ evidence = posterior

Observed x1.00
Prior P(spam)0.40
P(spam|x) = P(x|spam) × P(spam) / P(x)0.400P(spam)0.228P(x|spam)0.114P(x)0.802P(spam|x)×÷=
P(X|SPAM)
0.228
P(X|HAM)
0.038
P(SPAM|X)
0.802
P(HAM|X)
0.198
HOW P(x) IS CALCULATED
P(x) = P(x|spam)·P(spam) + P(x|ham)·P(ham)
= 0.228 × 0.40 + 0.038 × 0.60
= 0.1138

With a 40% prior on spam and observing x=1.0, the posterior favours spam at 80.2%. Drag the x slider towards the spam mean (2) to increase P(x|spam), or towards the ham mean (-1) to increase P(x|ham).

Step 3 of 6: The Naive Assumption

Features are independent

Actual correlation between features0.60
-3.5-1.80.01.83.5-3.5-1.80.01.83.5Feature 1Feature 2NB assumesActual
ACTUAL CORR
0.60
NB ASSUMED
0.00
NB ERROR %
60%
MODEL
Gaussian NB

High correlation violates the naive assumption significantly — yet NB often still works surprisingly well because it only needs the right class ranking, not calibrated probabilities.

Step 4 of 6: Combining Features

Multiplying independent likelihoods

Feature 1 (x₁) — spam μ=2, ham μ=-11.00
Feature 2 (x₂) — spam μ=1.5, ham μ=-0.50.80
Feature 1 (x₁=1.0)Feature 2 (x₂=0.8)0.228spam0.038ham0.346spam0.133ham×
NAIVE BAYES: MULTIPLY INDEPENDENT LIKELIHOODS
P(x₁|spam)·P(x₂|spam) = 0.228 × 0.346 = 0.0789
P(x₁|ham)·P(x₂|ham) = 0.038 × 0.133 = 0.0050
FROM JOINT LIKELIHOODS TO POSTERIOR (EQUAL PRIORS)
P(spam|x) = P(x|spam)·P(spam) / P(x)
= 0.0789 × 0.50 / (0.0395 + 0.0025)
= 0.940
JOINT SPAM
0.0789
JOINT HAM
0.0050
P(SPAM|X)
0.940
VERDICT
Spam

Both features combined favour spam (94.0%). The naive assumption lets us simply multiply P(x₁|spam) × P(x₂|spam) instead of modelling joint distributions. Try moving x₂ towards ham's mean (-0.5) to see the features disagree.

Step 5 of 6: Decision Boundary

Where posteriors are equal

Prior P(class A / spam)0.50
-4.0-1.80.52.85.0-3.0-1.30.52.34.0Feature 1Feature 2SpamHam
PRIOR RATIO
1.00
BOUNDARY SHIFT
-0.69
ACCURACY
99%
LOG PRIOR
0.00

With equal priors, the decision boundary depends only on the likelihoods — it sits where P(A|x) = P(B|x).

Step 6 of 6: Spam or Ham?

Text classification example

P(free|spam)0.80
P(money|spam)0.70
P(meeting|spam)0.10
P(hello|spam)0.30
P(prize|spam)0.75
Word Likelihoods: Spam vs Hamfree0.800.05money0.700.08meeting0.100.60hello0.300.55prize0.750.03P(word|spam)P(word|ham)
P(SPAM|WORDS)
0.995
P(HAM|WORDS)
0.005
TOP WORD
prize
VERDICT
SPAM

The combined word likelihoods favour spam (99.5%). The strongest spam signal is "prize" with a spam/ham ratio of 25.0. Try lowering spam-indicative words or raising ham-indicative ones to flip the verdict.