Decision Tree
Decision Tree
X1
4Y/3N
Disadvantage:
So, Weighted Gini Impurity for feature ‘GENDER’ is the lowest compared to the other two
features ‘COURSE’ and ‘HEIGHT’.
So, we will start splitting with ‘GENDER’.
RANGE OF GINI IMPURITY
Let us consider m outcomes, then
𝐺𝑖𝑛𝑖 𝐼𝑚𝑝𝑢𝑟𝑖𝑡𝑦 = 1 − σ𝑚 2 2 2 2
𝑖=1 𝑝𝑖 = 1 − 𝑝1 − 𝑝2 − … . . − 𝑝𝑚
For m = 2,
𝐺𝑖𝑛𝑖 𝐼𝑚𝑝𝑢𝑟𝑖𝑡𝑦 = 1 − σ2𝑖=1 𝑝𝑖2 = 1 − 𝑝12 − 𝑝22
where, p1 = p and p2 = 1- p
Case 1: Case 2:
Let us consider 2 outcomes Yes and No Let us consider 2 outcomes Yes and No
Worst Case: Number of Yes = Number of No, Best Case: All Yes and zero No,
then, P(Yes) = P(No) = 0.5 then, P(Yes) = 1 and P(No) = 0
𝐺𝑖𝑛𝑖 𝐼𝑚𝑝𝑢𝑟𝑖𝑡𝑦 = 1 − σ2𝑖=1 𝑝𝑖2
𝐺𝑖𝑛𝑖 𝐼𝑚𝑝𝑢𝑟𝑖𝑡𝑦 = 1 − σ2𝑖=1 𝑝𝑖2
= 1 − 𝑃(𝑌𝑒𝑠)2 −𝑃(𝑁𝑜)2
= 1 − 𝑃(𝑌𝑒𝑠)2 −𝑃(𝑁𝑜)2 = 1 – (1)2 – (0)2
= 1 – (0.5)2 – (0.5)2 =0
= 0.5
So, Gini Impurity lies between
0 and 0.5
Gini Impurity
Entropy, E(S)
E(S) = 0
Information Gain
Information Gain = Entropy – Information
Higher the Information Gain, more important is that feature
EXAMPLE
X1 X2 X3 X4 Y
Match Opponent Championship Time Location Win
1The Rock Tag Team Match Summer Texas No
2The Rock Tag Team Match Summer New York No
3Triple H Tag Team Match Summer Texas Yes
4Goldberg Inter Continental Match Summer Texas Yes
5Goldberg WWE Title Winter Texas Yes
6Goldberg WWE Title Winter New York No
7Triple H WWE Title Winter New York Yes
8The Rock Inter Continental Match Summer Texas No
9The Rock WWE Title Winter Texas Yes
10Goldberg Inter Continental Match Winter Texas Yes
11The Rock Inter Continental Match Winter New York Yes
12Triple H Inter Continental Match Summer New York Yes
13Triple H Tag Team Match Winter Texas Yes
14Goldberg Inter Continental Match Summer New York No
GI VS ENTROPY
Gini Impurity is computationally efficient compared to Entropy where we have to use
log 2 𝑝 which takes time. After entropy we again have to calculate Information Gain.
So, Gini Impurity is preferred over Entropy as the metric in Decision Tree to split the
nodes.
TYPES OF DECISION TREES