- Year not given
Buys computer: ID3 and Naive Bayes
Short answer
Root node is age (gain 0.247). ID3 tree: age=middle_aged → yes; age=young → student=yes → yes; age=senior → credit_rating=fair → yes. X (young,low,yes,fair) → yes. Naïve Bayes: (i) yes, (ii) yes, (iii) no.
Consider following training data (Buys Computer Data)
| SN | Age | income | student | credit_rating | class: buys_computer |
|---|---|---|---|---|---|
| 1 | Young | high | no | Fair | no |
| 2 | Young | high | no | Excellent | no |
| 3 | middle_aged | high | no | Fair | yes |
| 4 | Senior | medium | no | Fair | yes |
| 5 | Senior | low | yes | Fair | yes |
| 6 | Senior | low | yes | Excellent | no |
| 7 | middle_aged | low | yes | Excellent | yes |
| 8 | Young | medium | no | Fair | no |
| 9 | Young | low | yes | Fair | yes |
| 10 | Senior | medium | yes | Fair | yes |
| 11 | Young | medium | yes | Excellent | yes |
| 12 | middle_aged | medium | no | Excellent | yes |
| 13 | middle_aged | high | yes | Fair | yes |
| 14 | Senior | medium | no | Excellent | no |
a. Determine the root node of decision tree for above data set using ID3 algorithm. b. Draw the complete Decision Tree using ID3 algorithm and determine class for X={age = young, income = low, student = yes and credit rating = fair} c. Use Naïve Bayes Classifier to determine class for i. X={age = young, income = low, student = yes and credit rating = fair} ii. X={age = middle_aged, income = low and credit rating = excellent} iii. X={age = senior and credit rating = excellent}
Total tuples = 14: buys_computer = yes: 9, no: 5.
a. Root node using ID3
Entropy(D) = −(9/14)log₂(9/14) − (5/14)log₂(5/14) = 0.940
| Attribute | Value (yes, no) | Entropy of values | Weighted entropy | Gain |
|---|---|---|---|---|
| age | young (2, 3), middle (4, 0), senior (3, 2) | 0.971, 0, 0.971 | 5/14·0.971 + 0 + 5/14·0.971 = 0.694 | 0.940 − 0.694 = 0.247 |
| income | high (2, 2), medium (4, 2), low (3, 1) | 1.0, 0.918, 0.811 | 0.911 | 0.029 |
| student | no (3, 4), yes (6, 1) | 0.985, 0.592 | 0.788 | 0.152 |
| credit_rating | fair (6, 2), excellent (3, 3) | 0.811, 1.0 | 0.892 | 0.048 |
Answer: age has the highest gain (0.247), so the root node is age.
b. Complete decision tree
- middle_aged (4 yes, 0 no): pure, leaf = yes.
- young (2 yes, 3 no; E = 0.971): gains: income 0.571, student 0.971, credit 0.020, so split on student: no → no (3 records), yes → yes (2 records).
- senior (3 yes, 2 no): gains: income 0.020, student 0.020, credit 0.971, so split on credit_rating: fair → yes (3), excellent → no (2).
age?
young / middle \ senior
student? YES credit_rating?
no/ \yes fair/ \excellent
NO YES YES NO
X = (age = young, income = low, student = yes, credit = fair): age = young → student = yes → buys_computer = yes.
c. Naïve Bayes
P(yes) = 9/14 = 0.643, P(no) = 5/14 = 0.357. Attributes not given in X are left out.
i. X = (young, low, student = yes, fair)
- P(X | yes) = (2/9)(3/9)(6/9)(6/9) = 0.03292; × P(yes) = 0.02116
- P(X | no) = (3/5)(1/5)(1/5)(2/5) = 0.0096; × P(no) = 0.00343
- 0.02116 > 0.00343, so class = yes (probability about 86%).
ii. X = (middle_aged, low, credit = excellent)
- yes: (4/9)(3/9)(3/9)·(9/14) = 0.03175
- no: (0/5)(1/5)(3/5)·(5/14) = 0 (zero count for middle_aged with "no")
- Class = yes. With Laplacian correction: no = (5/14)(1/8)(2/8)(4/7) = 0.0064; yes = (9/14)(5/12)(4/12)(4/11) = 0.0325; the result is still yes.
iii. X = (senior, credit = excellent)
- yes: (3/9)(3/9)(9/14) = 0.0714
- no: (2/5)(3/5)(5/14) = 0.0857
- 0.0857 > 0.0714, so class = no (probability about 55%).
Answer: (i) yes, (ii) yes, (iii) no.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Play golf: ID3 and Naive Bayes · Data Mining, chapter 3
- Naive Bayes and Laplacian correction · Data Mining, chapter 3
- Naive Bayes advantages and disadvantages · Data Mining, chapter 3
- Central tendency; middle 70% income, median · Probability and Statistics, chapter 1
- Abstract Student class program · Object Oriented Programming, chapter 7