← AI-aktiviteter

Naïve Bayes Lab

An interactive classification lab

Svenska

Naïve Bayes Lab

Here you train a Naïve Bayes classifier — the same type of algorithm used in spam filters — and see the math behind every decision.

01
Train

Click Generate to fill the model with sample emails. You control the number and the ratio between spam and regular emails.

02
Explore the model

See what the model has learned — which words lean toward spam and which lean toward regular email, and how strongly.

03
Classify

Write your own email and press Enter. You get the model's answer with a confidence percentage — and can follow the whole calculation behind it.

Create training data

Each click adds more sample emails from a built-in bank. Vary the ratio to see how imbalanced training data affects the model.

Count:
Spam / not-spam ratio 50% / 50%
Even split — the prior probability P(class) barely affects the classification.
Statistics
Spam
0
examples
P(Spam) = —
Not spam
0
examples
P(Not spam) = —
Vocabulary: — words
Generate at least 2 examples to be able to train.
Training data 0 0
Write your own example
Class:
Import from file
A .csv or .txt — one example per line: SPAM,Your text here HAM,Your text here The label must be SPAM or HAM (uppercase).
📂
Click to choose a file
.csv or .txt · one example per line
No model yetAdd training data in the Train tab.
No model yetAdd training data in the Train tab.
Glossary

Click a term to open its explanation. The same explanations pop up when you click underlined words in the text.

Tokenization and filtering

Before the model can calculate probabilities, the text has to be broken into individual words — that's called tokenization. Words that are too common to say anything about the class (stop words) and very short words are then filtered out. Only the remaining words are used in the classification.

Used in the classification Stop word — filtered out (too common) Too short — filtered out (≤2 characters)

Note: no lemmatization is performed — "winning" and "winner" are counted as different words. Real systems often reduce words to their root form to improve accuracy.