Professional Documents
Culture Documents
Assignment-Decision Tree
Assignment-Decision Tree
Roll no:17271519-157
Assignment 3
------------------------------------------------------------------------------------------------------------------------------------------
= - (9/14log29/14) - (5/14log25/14)
=0.94
= 0.345 + 0.345
= 0.69
1
= 0.29 + 0.39 + 0.23
= 0.91
= 0.79
= 0.89
2
Age
<=30 31 to 40 >40 or 30
Buy = Yes
= 0.4
=0
= 0.97 – 0 = 0.97
3
Entropy (Credit_rating, Buys_computer) = P (fair) * Entropy (1, 2) + P (excellent) * Entropy
(1, 1)
= 0.95
= 0.95
= 0.95
= 3/5 * 0 + 2/5 * 0
=0
= 0.97 – 0 = 0.97
Age
<=30 31 to 40 >40 or 30
5
5. If age = >30 or >40 and credit rating = fair then buys_computer = no
= 1.58
= 1.56
=1
= 0.79 / 1 = 0.79
= 0.99
6
Credit_rating
Fair Excellent
= 1.56
= 0.345
7
SplitInfoincome (high, middle,low) = 1.56
SplitInfostudent (yes,no) = 1
= 4/8 * 1 + 4/8 * 0
= 0.5
= 0.31 / 1 = 0.31
8
Credit_rating
Fair Excellent
Student student
Yes No yes no
Gini index= 4/14*(1-((2/4) ^2 + (2/4) ^2)) +6/14*(1-((4/6) ^2 + (2/6) ^2)) +4/14*(1-((3/4) ^2 + (1/4)
^2)) =0.44
9
Calculating the Gini Index for Student:
Age
<=30 31 to 40 >40 or 30
Buy = Yes
Gini index= 2/5*(1-((0/2) ^2 + (2/2) ^2)) +2/5*(1-((1/2) ^2 + (1/2) ^2)) +1/5*(1-((1/1) ^2 + (0/1) ^2))
=0.2
10
Now, calculating Gini index when age >40,>30:
Age
<=30 31 to 40 >40 or 30
11
12