# Q4(b) Naive Bayes: flu [10]

Subject: Intelligent Systems II

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/is2/#tee/mocks/paper-final-2025/q4b

Canonical: https://deep-learning-study-room.vercel.app/read/is2/tee/mocks/paper-final-2025--q4b/

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)
$$



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

| Row | Fever | Cough | Temperature | Class |
| --- | --- | --- | --- | --- |
| 1 | Yes | Yes | High | Yes |
| 2 | No | No | Normal | No |
| 3 | Yes | No | Low | No |
| 4 | Yes | Yes | High | Yes |
| 5 | No | Yes | Normal | No |
| 6 | Yes | Yes | High | Yes |
| 7 | No | No | Low | No |
| 8 | Yes | No | Normal | No |

##### Step 2. Separate the two class groups

| Class | Rows in this group | Class count | Prior |
| --- | --- | --- | --- |
| Yes | 1, 4, 6 | 3 | 3/8 = 0.375 |
| No | 2, 3, 5, 7, 8 | 5 | 5/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}=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}=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}=0
$$



##### Step 6. Multiply the Yes score one factor at a time



$$
P(Yes)=3/8=0.375
$$





$$
0.375\times1=0.375
$$





$$
0.375\times1=0.375
$$





$$
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.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.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.6
$$



##### Step 10. Multiply the No score one factor at a time



$$
P(No)=5/8=0.625
$$





$$
0.625\times0.4=0.25
$$





$$
0.25\times0.2=0.05
$$





$$
0.05\times0.6=0.03
$$



##### Step 11. Compare the scores



$$
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.
