0% found this document useful (0 votes)
29 views12 pages

Gini Index Problem

The document explains the computation of the Gini Index for a decision tree using various attributes such as Weekend, Weather, Parents, and Money. It provides examples of how to calculate the Gini Index for different attributes and highlights the selection of the attribute with the smallest Gini Index for decision-making. Ultimately, it illustrates the process of determining the best attribute for splitting the dataset based on the Gini Index values.

Uploaded by

Jithin S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views12 pages

Gini Index Problem

The document explains the computation of the Gini Index for a decision tree using various attributes such as Weekend, Weather, Parents, and Money. It provides examples of how to calculate the Gini Index for different attributes and highlights the selection of the attribute with the smallest Gini Index for decision-making. Ultimately, it illustrates the process of determining the best attribute for splitting the dataset based on the Gini Index values.

Uploaded by

Jithin S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Decision Tree using Gini Index - Solved Example

Compute the Gini Index for the overall


Weekend| Weather Parents Money Decision
collection of training examples.
WI Sunny Yes Rich Cinema
W2 Sunny No Rich Tennis There are four possible output variables
W3 Windy Yes Rich Cinema Cinema, Tennis, Stay In and Shopping.
W4 Rainy Yes Poor Cinema The data has 6 instances of Cinema,
WS Rainy No Rich Stay In
W6 Rainy Yes Poor Cinema
2instances of Tennis, 1 instance of Stay In
W7 Windy No Poor Cinema and 1 of shopping.
W8 Windy No Rich Shopping 2
W9
W10
Windy Yes
No
Rich
Rich
Cinema
Tennis
Gini(S) = 1- ) +(+
Sunny
= 0.58

Subscribe to Mahesh Huddar Visit:vtupulse.com


Decision Tree using Gini Index - Solved Example
Computation of Gini Index for Money Attribute
Weekend| Weather Parents Money Decision It has two possibte vatues of Rich (7 examples) and
WI Sunny Yes Rich Cinema Poor (3 examples).
W2 Sunny No Rich Tennis For Money = Poor, there are 3examples with
"Cinema".
W3 Windy Yes Rich Cinema
W4 Rainy Yes Poor Cinema Gini(S) = 1- ]= 0v
WS Rainy No Rich Stay In For Money = Rich, there are 2 examples with
W6 Rainy Yes Poor Cinema "Tennis", 3 examples with "Cinema" and 1 example
WI No Poor Cinema with "Stay in", "Shopping" each
Windy
W8 Windy No Rich -Shopping Gini(S)) =1 +G)') =
Windy Yes Rich Cinema (0.694)
W10 Sunny No Rich Tennis

Subscribe to Mahesh Huddar Visit:vtupulse.com


Decision Tree using GiniIndex - Solved Example
Computation of GiniIndex for Money Attribute
Weekend|Weather Parents MoneyDecision It has two possibte vatues of Rich (7 examples) and
WI Sunny Yes Rich Cinema Poor (3 examples).
W2 Sunny No Rich Tennis For Money = Poor, there are 3 examples with
"Cinema".
W3 Windy Yes Rich -Cinema
W4 Rainy Yes Poor Cinema Gini(S) = 1- = 0v
WS Rainy No Rich Stay In For Money = Rich, there are 2 examples with
W6 Rainy Yes Poor Cinema "Tennis", 3 examples with "Cinema" and 1 example
WI Windy No Poor Cinema with "Stay in", "Shopping" each
W8 Windy No Rich -Shopping Gini(S) =1 + +()) =
W9 Windy Yes Rich Cinema 0.694)
W10 Sunny No Rich Tennis Weighted Average (Money)
3
= 0 * + 0.694 * =0.486
10

Subscribe to Mahesh Huddar Visit: vtupulse.com


Decision Tree using Gini Index - Solved Example
Computation of Gini Index for Parents Attribute
Weekend| Weather Parents Money Decision It has two possible values of Yes (5 examples) and No
Wi Sunny Yes. Rich Cinema (5 examples).
W2 Sunny No Rich Tennis For Parents =Yes, there are 5 examples, all with
"Cinema".
W3 Windy Yes Rich Cinema
W4 Rainy Yes PoUr Cinema Gini(S) = 1- I)j= 0
WS Rainy No Rieh Stay In For Parents No, there are 2 examples with "Tennis",
W6 Rainy Yes Poor Cinema 1 example with "Stay in", "Shopping" and "Cinema"
each
WI Windy No Poor Cinema
2

W8 Windy No. Rick


Rich
-Shopping Gini(S) = 1 ()+ +()+
W9 Windy Yes Cinema
(0.72)
W10 Sunny No Rich Tennis Weighted Average (Parents)
= 0 *
( + [0.72 *(o) = 0.36

Subscribe to Mahesh Huddar Visit: vtupulse.com


Decision Tree using Gini Index - Solved Example
Computation of Gini Index for Weather Attribute
Weekend Weather Parents Money Decision It has three possible values of Sunny (3 examples),
WI Sunny Yes Rich Cinema Rainy (3 examples) and Windy (4 examples).
W2 Sunny No Rich Tennis For Weather = Sunny, there are 2 examples with
W3 Windy Yes Rich Cinema "Cinema" and 1 with "Tennis".
W4 Rainy Yes Poor Cinema
WS Rainy No Rich Stay In Gini(Sunny) =1 - + i = 0.444
W6 Rainy Yes Poor Cinema For Weather = Rainy, there are 2 examples with
W? Windy No Poor Cinema "Cinema" and 1 example with "Stay in"
2
W8 Windy No Rich Shopping Gini(Rainy) = 1- +()]= 0.444
w9 Windy Yes Rich Cinema
For Weather = Windy, there are 3 examples with
W10 Sunny No Rich Tennis
"Cinema" and 1 example with "Shopping"
2

Gini(Windy) = 1- ( +()]
H) =0.375
Subscribe to Mahesh Huddar Visit: vtupulse.com
Decision Tree using Gini Index - Solved Example
Weekend| Weather
Weather Parents Money Decision Weighted Average( Weather)
Wi Sunny Yes Rich Cinema 4
W2 Sunny No Rich Tennis 0.444 * |+0.444
|+0.375()
W3 Windy Yes Rich Cinema
0.416
W4 Rainy Yes Poor Cinema
WS Rainy No Rich Stay In
W6 Yes Poor Cinema
For Weather - Gini Index:0.416
Rainy
WI Windy No Poor Cinema For Parents - Gini Index: 0.36 V
W8 Windy No Rich Shopping For Money - Gini Index: 0.486
W9 Windy Yes Rich Cinema
Parents is selected as it has smallest
W10 Sunny No Rich Tennis
Gini index.

Subscribe to Mahesh Huddar Visit:vtupulse.com


Decision Tree using Gini Index - Solved Example
Weekend Weather Parents Money Decision
W2 Surny No Rich Tennis
WS Rainy No Rich Stay In
WI Windy No Poor Cinema
W8 Windy No Rich Shopping
W10 Sunny No Rich Tennis

Computation of Gini Index for Parents = No |Weather Attribute


"Rainy (1 example).
For Parents = No |Weather = Rainy, there is l example with "Stay In".
2

"Gtni(S) = 1- ]= 0

Subscribe to Mahesh Huddar Visit: vtupulse.com


Decision Tree using GiniIndex - Solved Example
Weekend Weather Parents Money Decision
W2 Sunny No Rich Tennis
WS Rainy No Rich Stay In
WI Windy No Poor Cinema
W8 Windy No Rich Shopping
W10 Sunny No Rich Tennis

Computation of Gini Index for Parents = No |Weather Attribute


Windy (2 example)
For Parents = No |Weather = Windy, there is l example with "Cinema" and 1 example
with "Shopping".
Gint(s) =1- |) +)=0.5
Weighted Average (Parents = No | Weather) = 0 *
o)o.5-()-0z
Subscribe to Mahesh Huddar Visit: vtupulse.com
Decision Tree using Gini Index - Solved Example
Weekend Weather Parents Money Decision
W2 Sunny No Rich Ternis
WS Rainy No Rich Stay In
WI Windy No Poor Cinema
W8 Windy No Rich Shopping
W10 Sunny No Rich Tennis

Computation of Gini Index for Parents = No |Money Attribute


Rich (4 examples)
For Parents = No| Money= Rich, there is l example with "stay in" and "Shopping"
each and 2 examples of"Tennis".

Gini(5)
Gtnt(S) = 1-I)+ G + 1=0.625
Subscribe to Mahesh Huddar Visit:vtupulse.com
Decision Tree using GiniIndex - Solved Example
Weekend Weather Parents MoneyDecision
W2 Sunny No Rich Tennis
WS Rainy No Rich Stay In
WI Windy No Poor Cinema
W8 Windy No Rich Shopping
W10 Sunny No Rich Tennis

Computation of Gini Index for Parents = No| Money Attribute


Poor (1 example)
For Parents = No| Money = Poor, there is 1 example with "inema".

Gini(5) = 1- 4))o)
-
Welghted Average (Parents = No| Money) = 0.625 * (4/5) + 0* (1/5) =0.5

Subscribe to Mahesh Huddar Visit:vtupulse.com


Decision Tree using Gini Index - SolvedExample
Weekend Weather Parents Money Decision
W2 Sunny No Rich Tennis
WS Rainy No Rich Stay In
WI Windy No Poor Cinema
W8 Windy No Rich Shopping
W10 Sunny No Rich Tennis

For Parents = No|Weather - Gini Index: 0.2

For Parents = No |Money - Gini Index: 0.5

Weather is selected as it has smallest Gini index.

Subscribe to Mahesh Huddar Visit:vtupulse.com


Decision Tree using Gini Index - Solved Example
Weekend Weather Parents MoneyDecision
w2 Sunny No Rich Tennis
WS Rainy No Rich Stay In
WI Windy No Poor Cinema
W8 Windy No Rich Shopping
W10 Sunny No Rich Tenris

Now, for Parent=No &Weather=Sunny, we have all Now, for Parents=No &Weather=Rainy, we have all
instances as Tennis. instances as Stay In.
Weekend Weather Parents MoneyDecision Weekend Weather Parents Money Decision
W2 Sunny No Rich Tennis WS Rainy No Rich Stay In
W10 Sunny No Rich Tennis

Now, for Parent=No &Weather=Windy, we need to Weekend Weather Parents Money Decision

split. WI Windy No Poor Cinema


W8 Windy No Rich Shopping
Subscribe to Mahesh Huddar Visit:vtupulse.com

You might also like