Intelligent Systems II · TEE · mocks

Q4(b) Naive Bayes: flu [10]

Final examination · 24 Nov 2025

100-mark timed practice using the actual Final 2025 paper. Q1 compulsory; any four of Q2–Q7. Worked solutions are below the questions.

Question. A hospital wants to predict flu from Fever (Yes/No), Cough (Yes/No) and Temperature Level (Low/Normal/High). Training data: (Yes, Yes, High, Yes), (No, No, Normal, No), (Yes, No, Low, No), (Yes, Yes, High, Yes), (No, Yes, Normal, No), (Yes, Yes, High, Yes), (No, No, Low, No), (Yes, No, Normal, No). Using naive Bayes, predict whether a patient with Fever = Yes, Cough = Yes, Temperature = Normal has flu. [10 marks]

Answer

Given

The full training data are in Step 1. Query: Fever=Yes, Cough=Yes, Temperature=Normal. The main calculation uses unsmoothed counts.

To find

Both class scores and the predicted class.

Formula and why it applies

score(C)=P(C)\prod_jP(a_j\mid C)LaTeX: score(C)=P(C)\prod_jP(a_j\mid C)

C is a class label. Each aⱼ is one query feature value. First count inside a class, then multiply the prior and all three likelihoods.

Solution

Step 1. Write the training rows as a table
RowFeverCoughTemperatureClass
1YesYesHighYes
2NoNoNormalNo
3YesNoLowNo
4YesYesHighYes
5NoYesNormalNo
6YesYesHighYes
7NoNoLowNo
8YesNoNormalNo
Step 2. Separate the two class groups
ClassRows in this groupClass countPrior
Yes1, 4, 633/8 = 0.375
No2, 3, 5, 7, 855/8 = 0.625
Step 3. For class Yes, count Fever=Yes

Look only at class Yes rows 1, 4, 6. The matching rows are 1, 4, 6.

P(\text{Fever}=\text{Yes}\mid C=\text{Yes})=\frac{3}{3}=1LaTeX: P(\text{Fever}=\text{Yes}\mid C=\text{Yes})=\frac{3}{3}=1
Step 4. For class Yes, count Cough=Yes

Look only at class Yes rows 1, 4, 6. The matching rows are 1, 4, 6.

P(\text{Cough}=\text{Yes}\mid C=\text{Yes})=\frac{3}{3}=1LaTeX: P(\text{Cough}=\text{Yes}\mid C=\text{Yes})=\frac{3}{3}=1
Step 5. For class Yes, count Temperature=Normal

Look only at class Yes rows 1, 4, 6. No row in this class has that feature value.

P(\text{Temperature}=\text{Normal}\mid C=\text{Yes})=\frac{0}{3}=0LaTeX: P(\text{Temperature}=\text{Normal}\mid C=\text{Yes})=\frac{0}{3}=0
Step 6. Multiply the Yes score one factor at a time
P(Yes)=3/8=0.375LaTeX: P(Yes)=3/8=0.375
0.375\times1=0.375LaTeX: 0.375\times1=0.375
0.375\times1=0.375LaTeX: 0.375\times1=0.375
0.375\times0=0LaTeX: 0.375\times0=0
Step 7. For class No, count Fever=Yes

Look only at class No rows 2, 3, 5, 7, 8. The matching rows are 3, 8.

P(\text{Fever}=\text{Yes}\mid C=\text{No})=\frac{2}{5}=0.4LaTeX: P(\text{Fever}=\text{Yes}\mid C=\text{No})=\frac{2}{5}=0.4
Step 8. For class No, count Cough=Yes

Look only at class No rows 2, 3, 5, 7, 8. The matching rows are 5.

P(\text{Cough}=\text{Yes}\mid C=\text{No})=\frac{1}{5}=0.2LaTeX: P(\text{Cough}=\text{Yes}\mid C=\text{No})=\frac{1}{5}=0.2
Step 9. For class No, count Temperature=Normal

Look only at class No rows 2, 3, 5, 7, 8. The matching rows are 2, 5, 8.

P(\text{Temperature}=\text{Normal}\mid C=\text{No})=\frac{3}{5}=0.6LaTeX: P(\text{Temperature}=\text{Normal}\mid C=\text{No})=\frac{3}{5}=0.6
Step 10. Multiply the No score one factor at a time
P(No)=5/8=0.625LaTeX: P(No)=5/8=0.625
0.625\times0.4=0.25LaTeX: 0.625\times0.4=0.25
0.25\times0.2=0.05LaTeX: 0.25\times0.2=0.05
0.05\times0.6=0.03LaTeX: 0.05\times0.6=0.03
Step 11. Compare the scores
score(Yes)=0\qquad score(No)=0.03LaTeX: score(Yes)=0\qquad score(No)=0.03

The larger score belongs to No. Normalise only if a posterior probability is requested: divide each score by their total 0.03.

Final answer. Predict No. Yes score=0; No score=0.03.

The zero Yes score is caused by an absent training combination. If Laplace smoothing is explicitly required, apply it to all feature likelihoods in both classes. That is a different calculation and may change the prediction; do not mix smoothed and unsmoothed sides.

Yaad rakho: Class ke rows alag karo. Har feature ka count usi class ke total se divide. Saare factors multiply karo.