Intelligent Systems II · TEE · mocks

Q4(b) Naive Bayes: job offer [10]

Re-examination · 31 Jan 2026

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

Question. Predict whether a candidate accepts a job offer from Experience (Fresher/Mid/Senior), Expected Salary (Low/Medium/High) and Company Reputation (Good/Average). Data: (Fresher, Low, Good, Yes), (Mid, High, Good, Yes), (Senior, High, Average, No), (Fresher, Medium, Average, Yes), (Senior, Low, Good, No), (Mid, Medium, Good, Yes), (Fresher, High, Average, No), (Senior, Medium, Average, No). New candidate: Mid, Low, Good. [10 marks]

Answer

Given

The full training data are in Step 1. Query: Experience=Mid, Salary=Low, Reputation=Good. 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
RowExperienceSalaryReputationClass
1FresherLowGoodYes
2MidHighGoodYes
3SeniorHighAverageNo
4FresherMediumAverageYes
5SeniorLowGoodNo
6MidMediumGoodYes
7FresherHighAverageNo
8SeniorMediumAverageNo
Step 2. Separate the two class groups
ClassRows in this groupClass countPrior
Yes1, 2, 4, 644/8 = 0.5
No3, 5, 7, 844/8 = 0.5
Step 3. For class Yes, count Experience=Mid

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

P(\text{Experience}=\text{Mid}\mid C=\text{Yes})=\frac{2}{4}=0.5LaTeX: P(\text{Experience}=\text{Mid}\mid C=\text{Yes})=\frac{2}{4}=0.5
Step 4. For class Yes, count Salary=Low

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

P(\text{Salary}=\text{Low}\mid C=\text{Yes})=\frac{1}{4}=0.25LaTeX: P(\text{Salary}=\text{Low}\mid C=\text{Yes})=\frac{1}{4}=0.25
Step 5. For class Yes, count Reputation=Good

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

P(\text{Reputation}=\text{Good}\mid C=\text{Yes})=\frac{3}{4}=0.75LaTeX: P(\text{Reputation}=\text{Good}\mid C=\text{Yes})=\frac{3}{4}=0.75
Step 6. Multiply the Yes score one factor at a time
P(Yes)=4/8=0.5LaTeX: P(Yes)=4/8=0.5
0.5\times0.5=0.25LaTeX: 0.5\times0.5=0.25
0.25\times0.25=0.0625LaTeX: 0.25\times0.25=0.0625
0.0625\times0.75=0.046875LaTeX: 0.0625\times0.75=0.046875
Step 7. For class No, count Experience=Mid

Look only at class No rows 3, 5, 7, 8. No row in this class has that feature value.

P(\text{Experience}=\text{Mid}\mid C=\text{No})=\frac{0}{4}=0LaTeX: P(\text{Experience}=\text{Mid}\mid C=\text{No})=\frac{0}{4}=0
Step 8. For class No, count Salary=Low

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

P(\text{Salary}=\text{Low}\mid C=\text{No})=\frac{1}{4}=0.25LaTeX: P(\text{Salary}=\text{Low}\mid C=\text{No})=\frac{1}{4}=0.25
Step 9. For class No, count Reputation=Good

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

P(\text{Reputation}=\text{Good}\mid C=\text{No})=\frac{1}{4}=0.25LaTeX: P(\text{Reputation}=\text{Good}\mid C=\text{No})=\frac{1}{4}=0.25
Step 10. Multiply the No score one factor at a time
P(No)=4/8=0.5LaTeX: P(No)=4/8=0.5
0.5\times0=0LaTeX: 0.5\times0=0
0\times0.25=0LaTeX: 0\times0.25=0
0\times0.25=0LaTeX: 0\times0.25=0
Step 11. Compare the scores
score(Yes)=0.046875\qquad score(No)=0LaTeX: score(Yes)=0.046875\qquad score(No)=0

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

Final answer. Predict Yes. Yes score=0.046875; No score=0.
Official key note. The key gives No = 0.0068 and P(Yes) = 0.873. That No value comes from Laplace smoothing (1/7 × 2/7 × 2/6 × 0.5), but the key did not smooth the Yes side. If you smooth, smooth both: Yes = 0.5 × 3/7 × 2/7 × 4/6 = 0.0408, No = 0.0068, P(Yes) = 0.857. The prediction is Yes either way.

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