Skip to content
CampusEduX

Problem 3: Manually Apply Bayes' Theorem for Classification

Easypython
Learn the Concept: Naive Bayes

Problem Description

Write a Python program that manually calculates the Naive Bayes classification score for two classes, given prior probabilities and feature likelihoods (without using Scikit-learn), and determines the predicted class.

Input

Prior probabilities for two classes, and likelihood values for two features under each class.

Output

The calculated score for each class, and the predicted class.

Constraints

  • All probabilities are between 0 and 1.

Example Input

text
P(Spam)=0.4, P(NotSpam)=0.6 P(free|Spam)=0.6, P(free|NotSpam)=0.1 P(meeting|Spam)=0.05, P(meeting|NotSpam)=0.3 (email contains "free", not "meeting")

Example Output

text
Score(Spam): 0.228 Score(NotSpam): 0.042 Predicted class: Spam

Concepts Covered

Manual probability multiplication, Bayes' Theorem application.

Related Problems

  • Problem 1: Train a Gaussian Naive Bayes Classifier
    Easy · python
    Solve Problem
  • Problem 2: Predict Class Probabilities
    Easy · python
    Solve Problem
  • Problem 4: Compare Naive Bayes and Logistic Regression
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...