# Q4(b) Naive Bayes product-purchase classification [10]

Subject: Intelligent Systems II

Exam: TEE

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

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

Actual historical paper ·100 marks attempted /140 offered · Q1 compulsory + any four of Q2–Q7. Source defects and solution assumptions are explicitly identified.

**Question. Q4(b)** [10 marks · 2025-04-28]

| Age | Income Level | Previous Purchase | Buy Product |
| --- | --- | --- | --- |
| Young | Low | No | No |
| Middle-aged | Medium | Yes | Yes |
| Senior | High | No | No |
| Young | Medium | Yes | Yes |
| Senior | Low | No | No |
| Middle-aged | High | Yes | Yes |
| Young | Low | Yes | Yes |
| Senior | Medium | No | No |

A company wants to predict whether a customer will buy a product, based on the following features: Age (Young, Middle-aged, Senior), Income Level (Low, Medium, High), Previous Purchase (Yes, No). The output is Buy Product (Yes, No). Given a new customer with the following attributes: Age=Young, Income Level=High, Previous Purchase=No. Use Naive Bayes to predict whether this customer will buy the product.

### Answer

### Given

Eight training rows; query=(Young, High, No). No smoothing instruction is printed.

### To find

The two class scores and the larger-posterior class.

### Formula and why



$$
s_c=P(c)P(Young\mid c)P(High\mid c)P(PreviousNo\mid c)
$$



Naive Bayes assumes conditional independence of these features given the class. The evidence denominator is common to both classes, so compare the unnormalized scores first.

### Step 1. Count the classes

Yes occurs in rows 2,4,6,7:4 rows. No occurs in rows 1,3,5,8:4 rows.



$$
P(Yes)=4/8=1/2,\quad P(No)=4/8=1/2
$$



### Step 2. Count each query feature within each class

| Query feature | Count among Yes /4 | Count among No /4 |
| --- | --- | --- |
| Young | 2/4 | 1/4 |
| High income | 1/4 | 1/4 |
| Previous purchase No | 0/4 | 4/4 |

The denominator is the class count 4, not the full dataset 8.

### Step 3. Multiply the Yes score



$$
s_{Yes}=\frac12\times\frac24\times\frac14\times\frac04=0
$$



The zero comes from no training Yes row having Previous Purchase=No.

### Step 4. Multiply the No score



$$
s_{No}=\frac12\times\frac14\times\frac14\times\frac44=\frac1{32}=0.03125
$$



### Step 5. Normalize and predict



$$
P(Yes\mid x)=\frac0{0+0.03125}=0,\quad P(No\mid x)=\frac{0.03125}{0.03125}=1
$$



**Predicted class: No, under the unsmoothed model.** A posterior of 1 here is a consequence of tiny-data maximum-likelihood estimates and a zero conditional count; it is not certain knowledge about a real customer.

### Step 6. If smoothing is explicitly required, state the alternative

With add-one smoothing, Age and Income each have 3 categories and Previous Purchase has 2. Keep the class priors 1/2. Then:



$$
s_{Yes}^{(+1)}=\frac12\frac37\frac27\frac16=\frac1{98},\quad s_{No}^{(+1)}=\frac12\frac27\frac27\frac56=\frac5{147}
$$





$$
P_{+1}(Yes\mid x)=3/13,\quad P_{+1}(No\mid x)=10/13
$$



The decision is still No. This is a labeled alternative, not a silent change to the printed task.
