Naive Bayes Algorithm
1. What is Naive Bayes?
Naive Bayes Algorithm
1. What is Naive Bayes?
Naive Bayes is a supervised machine learning algorithm mainly used for classification tasks. It predicts the category or class of data based on probability.
The algorithm is based on Bayes’ Theorem and assumes that all input features are independent of each other, which is why it is called “Naive.”
Naive Bayes is widely used in text classification, sentiment analysis, spam filtering, and recommendation systems because it is simple, fast, and effective.

Examples:
- Email classification → Spam or Not Spam
- Movie review analysis → Positive or Negative
- News article classification → Sports, Politics, or Entertainment
- Medical diagnosis → Disease or No Disease
3. Bayes Theorem
Use this visual in your article:
P(A|B)=P(B|A)P(A)/P(B)
Meaning:
- P(A|B) → Probability of A given B
- P(B|A) → Probability of B given A
- P(A) → Prior probability
- P(B) → Evidence probability
Simple interpretation:
Posterior = Likelihood × Prior / Evidence
4. Why is it called “Naive”?
It assumes all features are independent.
Example:
For house price prediction:
- Size
- Location
- Bedrooms
Naive Bayes assumes they don’t affect each other (which is often not true).
That’s why it’s called “Naive”.
Visual 1: Working Flow
5. How Naive Bayes Works (Step-by-Step)
Step 1: Collect training data
Example:
Weather Prediction (Play Tennis or Not)
Imagine we want to teach the Naive Bayes model to predict:
“Should we play tennis today?”
To do this, we give the model past weather examples with the correct answers.
For example:
- Sunny, Hot, High Humidity, Not Windy → Do Not Play
- Sunny, Hot, High Humidity, Windy → Do Not Play
- Cloudy, Hot, High Humidity, Not Windy → Play
- Rainy, Mild, High Humidity, Not Windy → Play
- Rainy, Cool, Normal Humidity, Not Windy → Play
- Rainy, Cool, Normal Humidity, Windy → Do Not Play
- Cloudy, Cool, Normal Humidity, Windy → Play
Step 2: Calculate probabilities
Example:
Probability of Spam:
P(Spam)=2/3
Step 3: Check word probabilities
Example:
Probability of word “Free” in spam emails:
P(Free∣Spam)
Step 4: Multiply probabilities
Naive Bayes combines all probabilities and chooses the highest one.
Visual 2: Probability Example
Press enter or click to view image in full size
6. Types of Naive Bayes
Gaussian Naive Bayes
Used for continuous numerical data
Examples:
- Height
- Salary
- Temperature
Multinomial Naive Bayes
Used for text classification
Examples:
- Spam detection
- Sentiment analysis
Bernoulli Naive Bayes
Used for binary features (Yes/No)
Example:
- Contains word “free”? Yes/No
Conclusion
Naive Bayes is a simple, fast, and efficient machine learning classification algorithm based on probability and Bayes’ Theorem. It is especially useful for text classification tasks such as spam detection, sentiment analysis, and document categorization.
메타데이터
- post_id
- ee4c1311e2eb
- slug
- naive-bayes-algorithm-ee4c1311e2eb
- url
- https://medium.com/@kotturjyothi369/naive-bayes-algorithm-ee4c1311e2eb
- canonical_url
- https://medium.com/@kotturjyothi369/naive-bayes-algorithm-ee4c1311e2eb
- author_url
- https://medium.com/@kotturjyothi369
- status
- ok
- fetched_at
- 2026-06-21 15:33:18