Apply Decision Tree Algorithm On The Following Table and Construct Decision Tree Accordingly
Apply Decision Tree Algorithm On The Following Table and Construct Decision Tree Accordingly
Apply Decision Tree Algorithm On The Following Table and Construct Decision Tree Accordingly
Apply Decision tree Algorithm on the following table and construct decision tree accordingly.
Solution:
Buy_Computer
Yes No
Young 2 3 5
Middle 4 0 4
Age
Senior 2 3 5
14
= 0.971
Entropy(Middle) = Entropy(4/4, 0/4)
= -(1 log2 1)-(0 log2 0)
=0
Entropy(Senior) = Entropy(2/5, 3/5)
= -(0.4 log2 0.4)-(0.6 log2 0.6)
= 0.971
Entropy(Buy_Computer, Age) = P(Young)*E(Young) + P(Middle)*E(Middle) + P(Senior)*E(Senior)
= (5/14)*0.971 + (4/14)*0.0 + (5/14)*0.971
= 0.693
Gain(T,X) = Entropy(T) – Entropy(T,X)
Gain(Buy_Computer, Age) = E(Buy_Computer) – E(Buy_Computer, Age)
= 0.94 – 0.693
= 0.247
Buy_Computer
Yes No
High 2 2 4
Income Medium 4 2 6
Low 3 1 4
14
=1
= 0.9234
= 0.8112
Yes No
Yes 6 1 7
Student
No 3 4 7
14
= 0.4961
= 0.9851
Yes No
Fair 6 2 8
Credit_Rating
Excellent 3 3 6
14
= 0.8112
= 0.25
Choosing the attribute with the largest information gain as the decision node, divide the dataset
by its branches and repeat the same process on every branch. So the largest information gain is of
Gain(Buy_Computer, Age), so the decision node will start from Age.
Age Income Student Credit_Rating Buy_Computer
Middle High No Fair Yes
Middle Low Yes Excellent Yes
Middle Medium No Excellent Yes
Middle High Yes Fair Yes
The people who are young and are not student, they do not buy the computer and the people who are young
and are student always buy the computer. So the tree will be as;
Age Income Student Credit_Rating Buy_Computer
Senior Medium No Fair Yes
Senior Low Yes fair Yes
Senior Low Yes Excellent No
Senior Medium Yes Fair Yes
Senior Medium No Excellent No
The people who are senior and has excellent credit_rating they do not buy the computer and the people
who are senior and has fair credit_rating always buy the computer. So the tree will be as;