# Q2c · Animal categorical Naive Bayes

Subject: Natural Language Processing

Exam: TEE

Reader: https://deep-learning-study-room.vercel.app/nlp/#tee/papers/legacy-f24/q2c

Canonical: https://deep-learning-study-room.vercel.app/read/nlp/tee/papers/legacy-f24--q2c/

Previous examination · complete worked answers

**Question. Using the printed20-animal training table, classify an animal with Give Birth=Yes, Can Fly=No, Live in Water=Yes, Have Legs=No. Treat Name only as an identifier.** [10 marks]

### Answer

Rows below follow the source order: Human, Python, Salmon, Whale, Frog, Komodo, Bat, Pigeon, Cat, Leopard Shark, Turtle, Penguin, Porcupine, Eel, Salamander, Gila Monster, Platypus, Owl, Dolphin, Eagle. The source assigns Leopard Shark to Non-mammals and Platypus to Mammals; retain those labels.

### Given

| Give Birth | Can Fly | Live in Water | Have Legs | Class |
| --- | --- | --- | --- | --- |
| Yes | No | No | Yes | Mammals |
| No | No | No | No | Non-mammals |
| No | No | Yes | No | Non-mammals |
| Yes | No | Yes | No | Mammals |
| No | No | Sometimes | Yes | Non-mammals |
| No | No | No | Yes | Non-mammals |
| Yes | Yes | No | Yes | Mammals |
| No | Yes | No | Yes | Non-mammals |
| Yes | No | No | Yes | Mammals |
| Yes | No | Yes | No | Non-mammals |
| No | No | Sometimes | Yes | Non-mammals |
| No | No | Sometimes | Yes | Non-mammals |
| Yes | No | No | Yes | Mammals |
| No | No | Yes | No | Non-mammals |
| No | No | Sometimes | Yes | Non-mammals |
| No | No | No | Yes | Non-mammals |
| No | No | No | Yes | Mammals |
| No | Yes | No | Yes | Non-mammals |
| Yes | No | Yes | No | Mammals |
| No | Yes | No | Yes | Non-mammals |

Test: {'Give Birth': 'Yes', 'Can Fly': 'No', 'Live in Water': 'Yes', 'Have Legs': 'No'}

### To find

Class under categorical Naive Bayes.

### Formula: which one and why



$$
\mathrm{score}(c)=P(c)\prod_jP(x_j\mid c)
$$



Use empirical categorical frequencies, not a multinomial word model. No likelihood is zero for the requested test, so unsmoothed estimates are sufficient. Each feature contributes once; ignore names/identifiers as predictors.

### Step 1. Count examples in each class

| Class | Count | Prior |
| --- | --- | --- |
| Mammals | 7 | 7/20 |
| Non-mammals | 13 | 13/20 |

### Step 2. Count each requested feature within each class and multiply

| Class | n | Prior | Give Birth | Can Fly | Live in Water | Have Legs | Exact product | Decimal product |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Mammals | 7 | 7/20 | 6/7 | 6/7 | 2/7 | 2/7 | 36/1715 | 0.020991253644 |
| Non-mammals | 13 | 13/20 | 1/13 | 10/13 | 3/13 | 4/13 | 6/2197 | 0.002730996814 |

### Step 3. Normalize for a posterior if wanted

| Class | Score / score sum |
| --- | --- |
| Mammals | 0.884876150 |
| Non-mammals | 0.115123850 |

### Final answer

**Predicted class: Mammals.** The independence assumption is conditional on class, not a claim that these biological/weather features are truly independent.
