Decision-tree Visualization
Sash Saseetharran
Pre-Requisites
• Basic understanding of data exploration,
machine learning, and Python
Learning Objectives
• Visualizing a decision tree by hand
• Running a test case
Agenda
• Part I
Explore data
Visualize
• Part II
Let’s do it together
• Part III
Students try in pairs
• Part IV
Galvanize the understanding
Closing
Part I
Visualize the tree
Predict if Peter will Play Golf?
Day Outlook Temp Humidity Windy Play
1 sunny hot high false No
2 sunny hot high true No
3 overcast hot high false Yes
4 rain mild high false Yes
5 rain cool normal false Yes
6 rain cool normal true No
7 overcast cool normal true Yes
8 sunny mild high false No
9 sunny cool normal false Yes
10 rain mild normal false Yes
11 sunny mild normal true Yes
12 overcast mild high true Yes
13 rain mild high true No
14 rain hot normal false
Predict if Peter will Play ... Contd
From the given Golf data:
13 training samples
One test case
Within the training data, 8 Yes & 5 No
Independent Predictor variables:
• Outlook, Temperature, Humidity & Windy
How many levels?
• 2 levels: Humidity, Windy & Play
• 3 levels: Outlook & Temp
Predict if Peter will Play Golf?
Day Outlook Temp Humidity Windy Play
1 sunny hot high false No
2 sunny hot high true No
3 overcast hot high false Yes
4 rain mild high false Yes
5 rain cool normal false Yes
6 rain cool normal true No
7 overcast cool normal true Yes
8 sunny mild high false No
9 sunny cool normal false Yes
10 rain mild normal false Yes
11 sunny mild normal true Yes
12 overcast mild high true Yes
13 rain mild high true No
14 rain hot normal false
Predict if Peter will Play Golf?
Terminal Node
(Leaf)
Root Node
Predict if Peter will Play Golf?
Day Outlook Temp Humidity Windy Play
1 sunny hot high false No
2 sunny hot high true No
3 overcast hot high false Yes
4 rain mild high false Yes
5 rain cool normal false Yes
6 rain cool normal true No
7 overcast cool normal true Yes
8 sunny mild high false No
9 sunny cool normal false Yes
10 rain mild normal false Yes
11 sunny mild normal true Yes
12 overcast mild high true Yes
13 rain mild high true No
14 rain hot normal false
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Day Temp Humidity Windy
Rain
3 hot high false
7 cool normal true
12 mild high true
3 Yes + 0 No
Terminal Node (Leaf)
Part II
Let’s do it together!
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Yes (3) Rain
Day Temp Humidity Windy
1 hot high false
2 hot high true
8 mild high false
9 cool normal false
11 mild normal true
2 Yes + 3 No
More splitting is needed
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Yes (3) Rain
Day Temp Humidity Windy
1 hot high false
2 hot high true
8 mild high false
9 cool normal false
11 mild normal true
2 Yes + 3 No
More splitting is needed
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
no
yes
Day Humidity Windy Day Humidity Windy
1 high false
9 normal false
2 high true
11 normal true
8 high false
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
yes no
No Yes
(3) (2)
Part III
Students in pairs
(4 mins)
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ? Day Temp Humidity Windy
4 mild high false
yes no
5 cool normal false
No Yes 6 cool normal true
(3) (2) 10 mild normal false
13 mild high true
3 Yes + 2 No
More splitting is needed
Decision Tree
8 Yes + 5 No
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ? Day Temp Humidity Windy
4 mild high false
yes no
5 cool normal false
No Yes 6 cool normal true
(3) (2) 10 mild normal false
13 mild high true
3 Yes + 2 No
More splitting is needed
Learned Decision Tree
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
Windy ?
yes no
yes no
No Yes
No Yes
(3) (2)
(2) (3)
Terminal Nodes (Leaf)
Prediction?
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
Windy ?
yes no
yes no
No Yes
No Yes
(3) (2) (2) (3)
Day Outlook Temp Humidity Windy
14 rain hot normal false
Prediction?
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
Windy ?
yes no
yes no
No Yes
No Yes
(3) (2) (2) (3)
Day Outlook Temp Humidity Windy
14 rain hot normal false
Prediction?
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
Windy ?
yes no
yes no
No Yes
No Yes
(3) (2) (2) (3)
Day Outlook Temp Humidity Windy
14 rain hot normal false
Prediction?
Outlook
Overcast
Sunny Yes (3) Rain
High Humidity ?
Windy ?
yes no
yes no
No Yes No Yes
(3) (2) (2) (3)
Day Outlook Temp Humidity Windy
14 rain hot normal false
Part IV
Review
Predict if Peter will Play Golf?
Day Outlook Temp Humidity Windy Play
1 sunny hot high false No
2 sunny hot high true No
3 overcast hot high false Yes
4 rain mild high false Yes
5 rain cool normal false Yes
6 rain cool normal true No
7 overcast cool normal true Yes
8 sunny mild high false No
9 sunny cool normal false Yes
10 rain mild normal false Yes
11 sunny mild normal true Yes
12 overcast mild high true Yes
13 rain mild high true No
14 rain hot normal false
Predict if Peter will Play Golf?
Day Outlook Temp Humidity Windy Play
1 sunny hot high false No
2 sunny hot high true No
3 overcast hot high false Yes
4 rain mild high false Yes
5 rain cool normal false Yes
6 rain cool normal true No
7 overcast cool normal true Yes
8 sunny mild high false No
9 sunny cool normal false Yes
10 rain mild normal false Yes
11 sunny mild normal true Yes
12 overcast mild high true Yes
13 rain mild high true No
14 rain hot normal false
Splitting at the Nodes
• Entropy (information gain)
• Gini Impurity
Learned Decision Tree
Outlook Root Node
Overcast
Sunny Yes (3) Rain
High Humidity ?
Windy ?
yes no
yes no
No Yes
No Yes
(3) (2)
(2) (3)
Terminal Nodes (Leaf)
Assumptions
• It is assumed that the attributes outside the
ones from the given table has no effect during
the life of the decision tree
Q&A