Skip to main content

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)

SNAgeincomestudentcredit_ratingclass: buys_computer
1YounghighnoFairno
2YounghighnoExcellentno
3middle_agedhighnoFairyes
4SeniormediumnoFairyes
5SeniorlowyesFairyes
6SeniorlowyesExcellentno
7middle_agedlowyesExcellentyes
8YoungmediumnoFairno
9YounglowyesFairyes
10SeniormediumyesFairyes
11YoungmediumyesExcellentyes
12middle_agedmediumnoExcellentyes
13middle_agedhighyesFairyes
14SeniormediumnoExcellentno

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

AttributeValue (yes, no)Entropy of valuesWeighted entropyGain
ageyoung (2, 3), middle (4, 0), senior (3, 2)0.971, 0, 0.9715/14·0.971 + 0 + 5/14·0.971 = 0.6940.940 − 0.694 = 0.247
incomehigh (2, 2), medium (4, 2), low (3, 1)1.0, 0.918, 0.8110.9110.029
studentno (3, 4), yes (6, 1)0.985, 0.5920.7880.152
credit_ratingfair (6, 2), excellent (3, 3)0.811, 1.00.8920.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)

All Data Mining chapter 3 questions →