Bayesian Classification

Probabilistic approach to machine learning classification

What is Bayesian Classification?

Definition: Bayesian Classification is a probabilistic machine learning approach that uses Bayes' theorem to predict the class of a data point based on prior knowledge and observed evidence.

Unlike deterministic classifiers, Bayesian classifiers calculate the probability of each class given the input features, then assign the class with the highest probability. This probabilistic approach makes them robust to noise and uncertainty.

Key Advantage: Bayesian classifiers provide not just predictions but also confidence levels (probabilities), making them valuable for decision-making under uncertainty.

Bayes' Theorem

P(C|X) = [P(X|C) × P(C)] / P(X)

Where:

  • P(C|X) = Posterior probability: Probability of class C given features X
  • P(X|C) = Likelihood: Probability of features X given class C
  • P(C) = Prior probability: Initial probability of class C
  • P(X) = Evidence: Total probability of observing features X

Classification Decision Rule

Assign data point X to class C* where:

C* = argmaxC P(C|X) = argmaxC P(X|C) × P(C)

Note: P(X) is constant for all classes, so we can ignore it for classification.

Naive Bayes Classifier

Naive Assumption: All features are conditionally independent given the class. This "naive" assumption simplifies computation while often maintaining good performance.

Simplified Formula

For features X = (x₁, x₂, ..., xₙ):

P(C|X) ∝ P(C) × ∏i=1n P(xi|C)

Why "Naive"?

The independence assumption is rarely true in real data (e.g., word frequencies in text are correlated), but Naive Bayes often works well despite this simplification.

Types of Naive Bayes Classifiers

Gaussian Naive Bayes

Use Case: Continuous features

Assumption: Features follow normal distribution

Example: Height, weight, temperature measurements

Multinomial Naive Bayes

Use Case: Discrete count data

Assumption: Features represent frequencies

Example: Word counts in text classification

Bernoulli Naive Bayes

Use Case: Binary features

Assumption: Features are boolean (present/absent)

Example: Document contains specific keywords (yes/no)

Complement Naive Bayes

Use Case: Imbalanced datasets

Advantage: Better performance on skewed class distributions

Example: Rare disease diagnosis

Real-World Applications

Spam Filtering

Email classification as spam or not spam based on word frequencies. One of the most successful applications of Naive Bayes.

Sentiment Analysis

Determining whether text expresses positive, negative, or neutral sentiment in product reviews or social media.

Document Classification

Categorizing news articles, research papers, or web pages into topics (sports, politics, technology, etc.).

Medical Diagnosis

Predicting disease probability based on symptoms and test results, accounting for prior disease prevalence.

Recommendation Systems

Predicting user preferences for products or content based on past behavior and demographics.

Real-time Prediction

Fast classification for applications requiring immediate decisions, like fraud detection or intrusion detection.

Worked Example: Email Spam Classification

Problem Setup

Classify an email as Spam or Not Spam based on word presence.

Training Data:

  • Total emails: 100 (60 Not Spam, 40 Spam)
  • Word "free" appears in: 5 Not Spam, 30 Spam emails
  • Word "meeting" appears in: 40 Not Spam, 2 Spam emails

Step 1: Calculate Prior Probabilities

  • P(Spam) = 40/100 = 0.40
  • P(Not Spam) = 60/100 = 0.60

Step 2: Calculate Likelihoods

For Spam:

  • P("free"|Spam) = 30/40 = 0.75
  • P("meeting"|Spam) = 2/40 = 0.05

For Not Spam:

  • P("free"|Not Spam) = 5/60 = 0.083
  • P("meeting"|Not Spam) = 40/60 = 0.667

Step 3: Classify New Email

Email contains: "free" and "meeting"

For Spam:

P(Spam|X) ∝ 0.40 × 0.75 × 0.05 = 0.015

For Not Spam:

P(Not Spam|X) ∝ 0.60 × 0.083 × 0.667 = 0.033

Decision: 0.033 > 0.015 → Classify as Not Spam

Advantages & Limitations

Advantages Limitations
Simple and fast to train Independence assumption rarely holds
Works well with small datasets Zero-frequency problem (use Laplace smoothing)
Handles high-dimensional data Poor estimator of probabilities (but good classifier)
Provides probability estimates Assumes features are equally important
Not sensitive to irrelevant features Cannot learn feature interactions

Key Takeaways

Remember:
  • Bayesian classification uses Bayes' theorem for probabilistic predictions
  • Naive Bayes assumes feature independence (naive but effective)
  • Excellent for text classification and spam filtering
  • Fast training and prediction, suitable for real-time applications
  • Works well even when independence assumption is violated
  • Choose variant based on feature type: Gaussian, Multinomial, or Bernoulli