Classifying a Patient Using Naive Bayes Probabilities

Last updated

Problem Setup

Scenario:Determine whether a patient is likely to have a Viral or Healthy diagnosis from a set of observed symptoms.

Given:Ten historical patient records with Fever, Fatigue, Cough, and Headache observations, each paired with a known diagnosis.

Task:Apply categorical Naive Bayes without smoothing: calculate the class priors and conditional probabilities for a patient with High fever, Fatigue = Yes, Cough = Yes, and Headache = Yes, then compare the class scores to predict the diagnosis.

Need a quick refresher? Review Naive Bayes theory

Patient Symptoms & Diagnosis

Each record pairs four observed symptoms with a known diagnosis. These labeled observations provide the counts needed to establish the prior class probabilities and measure how frequently each symptom occurs within the Viral and Healthy groups.

Data Point
Fever✎
Fatigue✎
Cough✎
Headache✎
Diagnosis
P1
High
Yes
Yes
Yes
Viral
P2
High
Yes
No
Yes
Viral
P3
Normal
No
Yes
No
Healthy
P4
Normal
No
No
No
Healthy
P5
High
No
Yes
Yes
Viral
P6
Normal
Yes
No
Yes
Healthy
P7
High
Yes
Yes
No
Viral
P8
Normal
No
Yes
Yes
Healthy
P9
Normal
Yes
Yes
No
Healthy
P10
High
Yes
No
No
Viral
Target
High
Yes
Yes
Yes
?

Step-by-Step Solution

Step 1: Calculate Prior Probabilities P (Class)

Formula: P(c)=Count of Class cTotal Data PointsP(c) = \dfrac{\text{Count of Class } c}{\text{Total Data Points}}
P (Viral)
= 5 / 10
= 0.5
P (Healthy)
= 5 / 10
= 0.5

Step 2: Calculate Conditional Probabilities P (Feature | Class)

Formula: P(xi∣c)=Count of xi within Class cTotal Count of Class cP(x_i | c) = \dfrac{\text{Count of } x_i \text{ within Class } c}{\text{Total Count of Class } c}
For Class: Viral
P (Fever = High | Viral)= 5/5
P (Fatigue = Yes | Viral)= 4/5
P (Cough = Yes | Viral)= 3/5
P (Headache = Yes | Viral)= 3/5
For Class: Healthy
P (Fever = High | Healthy)= 0/5
P (Fatigue = Yes | Healthy)= 2/5
P (Cough = Yes | Healthy)= 3/5
P (Headache = Yes | Healthy)= 2/5

Step 3: Calculate Class Scores and Select the Prediction

Formula: Score(c)=P(c)∏i=1nP(xi∣c)\mathrm{Score}(c) = P(c) \prod_{i=1}^{n} P(x_i \mid c)
Class Score: Viral

= 5/10 * 5/5 * 4/5 * 3/5 * 3/5

= 0.144

Class Score: Healthy

= 5/10 * 0/5 * 2/5 * 3/5 * 2/5

= 0

Final Answer

Prediction:Viral

Fever = High has zero observed frequency in the Healthy class, making its unsmoothed class score zero. The Viral class receives a positive score, so it is selected. This prediction is based on the given training records and the Naive Bayes independence assumption.

Exam Takeaway

  • Keep likelihoods class-specific: Calculate P(xi∣c)P(x_i \mid c) using only the training records belonging to class cc. The same feature value can have different conditional probabilities for different classes, so always check the denominator.
  • Understand the zero-frequency problem: Without smoothing, a single zero conditional probability makes the entire class score zero. Laplace smoothing can prevent this by adding one to each category count and adjusting the denominator to include the number of possible categories.
  • Distinguish class scores from posterior probabilities: Multiplying the prior by the feature likelihoods gives an unnormalized score. These scores are sufficient for choosing the most likely class, but they must be normalized before being interpreted as posterior probabilities.