Data Mining Exercise 8

Decision Tree - Information Gain vs Gini Index for selecting the best Attribute

Warning

This article is a work in progress and may contain incomplete information or inaccuracies. Please verify details from reliable sources.

Data Mining Exercise 8

πŸ“Œ Precaution

In the data table for question 5, some Class Label cells are "blank" (no + sign). I will assume those blank cells are negative class (-) to make it a Binary Class Problem according to the problem.


ABClass Label

-----| |T|F|+| |T|T|+| |T|T|+| |T|F|-| |T|T|+| |F|F|-| |F|F|-| |F|F|-| |T|T|-| |T|F|-|

Question 5: Selecting Attribute A or B

Data Summary

Total data count 10 rows

  • Class (+): 4 people (Rows 1, 2, 3, 5)
  • Class (-): 6 people (Rows 4, 6, 7, 8, 9, 10)

5a. Calculate Information Gain (Choose A or B?)

Entropy Formula

H(S)=βˆ’p+log⁑2p+βˆ’pβˆ’log⁑2pβˆ’H(S) = -p_+ \log_2 p_+ - p_- \log_2 p_-

Entropy of Parent (P)

p+=410=0.4,pβˆ’=610=0.6p_+ = \frac{4}{10} = 0.4, \quad p_- = \frac{6}{10} = 0.6

H(P)=βˆ’(0.4log⁑20.4)βˆ’(0.6log⁑20.6)β‰ˆ0.971H(P) = -(0.4 \log_2 0.4) - (0.6 \log_2 0.6) \approx \mathbf{0.971}

Information Gain of Attribute A

A = T (7 people): has (+)4, (-)3

H(AT)=βˆ’(4/7log⁑24/7)βˆ’(3/7log⁑23/7)β‰ˆ0.985H(A_T) = -(4/7 \log_2 4/7) - (3/7 \log_2 3/7) \approx 0.985

A = F (3 people): has (+)0, (-)3 (Pure)

H(AF)=βˆ’(0)βˆ’(1log⁑21)=0H(A_F) = -(0) - (1 \log_2 1) = 0

Weighted Entropy:

710(0.985)+310(0)=0.6895\frac{7}{10}(0.985) + \frac{3}{10}(0) = 0.6895

Information Gain(A):

0.971βˆ’0.6895=0.28150.971 - 0.6895 = \mathbf{0.2815}

Information Gain of Attribute B

B = T (4 people): has (+)3, (-)1

H(BT)=βˆ’(0.75log⁑20.75)βˆ’(0.25log⁑20.25)β‰ˆ0.811H(B_T) = -(0.75 \log_2 0.75) - (0.25 \log_2 0.25) \approx 0.811

B = F (6 people): has (+)1, (-)5

H(BF)=βˆ’(1/6log⁑21/6)βˆ’(5/6log⁑25/6)β‰ˆ0.650H(B_F) = -(1/6 \log_2 1/6) - (5/6 \log_2 5/6) \approx 0.650

Weighted Entropy:

410(0.811)+610(0.650)=0.3244+0.39=0.7144\frac{4}{10}(0.811) + \frac{6}{10}(0.650) = 0.3244 + 0.39 = 0.7144

Information Gain(B):

0.971βˆ’0.7144=0.25660.971 - 0.7144 = \mathbf{0.2566}

Summary 5a

βœ… Choose Attribute A

Because Gain(A) = 0.2815 > Gain(B) = 0.2566


5b. Calculate Gain in Gini Index (Choose A or B?)

Gini Index Formula

Gini(S)=1βˆ’βˆ‘pi2\text{Gini}(S) = 1 - \sum p_i^2

Gini of Parent (P)

Gini(P)=1βˆ’[(0.4)2+(0.6)2]=1βˆ’(0.16+0.36)=0.48\text{Gini}(P) = 1 - [(0.4)^2 + (0.6)^2] = 1 - (0.16 + 0.36) = \mathbf{0.48}

Gini of Attribute A

A = T:

1βˆ’[(4/7)2+(3/7)2]=1βˆ’(0.327+0.184)β‰ˆ0.4891 - [(4/7)^2 + (3/7)^2] = 1 - (0.327 + 0.184) \approx 0.489

A = F:

1βˆ’[02+12]=01 - [0^2 + 1^2] = 0

Weighted Gini:

710(0.489)+310(0)=0.3423\frac{7}{10}(0.489) + \frac{3}{10}(0) = \mathbf{0.3423}

Gain Gini(A):

0.48βˆ’0.3423=0.13770.48 - 0.3423 = \mathbf{0.1377}

Gini of Attribute B

B = T:

1βˆ’[(0.75)2+(0.25)2]=1βˆ’(0.5625+0.0625)=0.3751 - [(0.75)^2 + (0.25)^2] = 1 - (0.5625 + 0.0625) = 0.375

B = F:

1βˆ’[(1/6)2+(5/6)2]=1βˆ’(0.028+0.694)β‰ˆ0.2781 - [(1/6)^2 + (5/6)^2] = 1 - (0.028 + 0.694) \approx 0.278

Weighted Gini:

410(0.375)+610(0.278)=0.15+0.1668=0.3168\frac{4}{10}(0.375) + \frac{6}{10}(0.278) = 0.15 + 0.1668 = \mathbf{0.3168}

Gain Gini(B):

0.48βˆ’0.3168=0.16320.48 - 0.3168 = \mathbf{0.1632}

Summary 5b

βœ… Choose Attribute B

Because Gain Gini(B) = 0.1632 > Gain Gini(A) = 0.1377


5c. Explanation - Can we choose different Attributes?

Answer

βœ… Possible (Yes)

As seen in this example (Info Gain chose A but Gini chose B)

Reason

Information Gain (Entropy):

  • Tends to be biased towards Attributes that divide into the most "Pure" subgroups.
  • Even if that group is small (e.g. A=F only has 3 people, but 100% pure, making Entropy drop drastically).

Gini Index:

  • Tends to prefer divisions that result in "large and moderately pure" groups rather than small, highly pure groups.
  • Gini will not drop as fast as Entropy when it encounters a small Pure node.

Question 6: Gini Index of Node Splitting

PC1C2
Class 0734
Class 1303

Data

  • Parent (P): Class 0 = 7, Class 1 = 3 (Total 10)
  • Child 1 (C1): Class 0 = 3, Class 1 = 0 (Total 3) β†’ Pure
  • Child 2 (C2): Class 0 = 4, Class 1 = 3 (Total 7)

6a. Calculate Gini index of node P

Gini(P)=1βˆ’[(710)2+(310)2]\text{Gini}(P) = 1 - \left[ \left(\frac{7}{10}\right)^2 + \left(\frac{3}{10}\right)^2 \right]

Gini(P)=1βˆ’[0.49+0.09]=1βˆ’0.58=0.42\text{Gini}(P) = 1 - [0.49 + 0.09] = 1 - 0.58 = \mathbf{0.42}


6b. Calculate Weighted Gini index & Decision

Gini of Child 1 (C1)

This group only has Class 0 (Pure).

Gini(C1)=1βˆ’[(3/3)2+(0/3)2]=1βˆ’1=0\text{Gini}(C1) = 1 - [(3/3)^2 + (0/3)^2] = 1 - 1 = \mathbf{0}

Gini of Child 2 (C2)

Gini(C2)=1βˆ’[(4/7)2+(3/7)2]=1βˆ’[0.3265+0.1837]β‰ˆ1βˆ’0.51=0.49\text{Gini}(C2) = 1 - [(4/7)^2 + (3/7)^2] = 1 - [0.3265 + 0.1837] \approx 1 - 0.51 = \mathbf{0.49}

Weighted Gini

WeightedΒ Gini=310Γ—Gini(C1)+710Γ—Gini(C2)\text{Weighted Gini} = \frac{3}{10} \times \text{Gini}(C1) + \frac{7}{10} \times \text{Gini}(C2)

=(0.3Γ—0)+(0.7Γ—0.49)=0.343= (0.3 \times 0) + (0.7 \times 0.49) = \mathbf{0.343}

Decision Summary

πŸ“Š Comparison Result

  • Old Gini: 0.42
  • New Gini (Weighted): 0.343
  • Reduced value (Gain): 0.42 - 0.343 = 0.077

βœ… Should Consider (Yes)

Because Gini value decreased, it means the data purity increased (Impurity decreased), especially Node C1 which split out to be 100% pure.

AI Knowledge Assistant

ΰΈͺΰΈ§ΰΈ±ΰΈͺΰΈ”ΰΈ΅ΰΈ„ΰΈ£ΰΈ±ΰΈš! ΰΈœΰΈ‘ΰΈ„ΰΈ·ΰΈ­ AI Assistant ΰΈ›ΰΈ£ΰΈ°ΰΈˆΰΈ³ΰΉ€ΰΈ§ΰΉ‡ΰΈšΰΉ„ΰΈ‹ΰΈ•ΰΉŒ

ΰΈ„ΰΈΈΰΈ“ΰΈͺΰΈ²ΰΈ‘ΰΈ²ΰΈ£ΰΈ–ΰΈͺΰΈ­ΰΈšΰΈ–ΰΈ²ΰΈ‘ΰΈ‚ΰΉ‰ΰΈ­ΰΈ‘ΰΈΉΰΈ₯ΰΈ”ΰΉ‰ΰΈ²ΰΈ™ Computer Science, Business, ΰΈ«ΰΈ£ΰΈ·ΰΈ­ Finance ΰΉ„ΰΈ”ΰΉ‰ΰΉ€ΰΈ₯ΰΈ’ΰΈ„ΰΈ£ΰΈ±ΰΈš