Skip to content
C

Problem 3: Manually Apply Bayes' Theorem for Classification

Easypython

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.

Input (stdin)

Output

Run your code to see output here...