Decision Tree Gear Up!
CS200 | Spring 2023
What We’ll Be Covering
Learning objectives
Intro
The Assignment
You will be generating a decision tree that can predict output values from input values.
But what is a decision tree?
squash
orange
high carb
high fiber
likeToEat
true
decision tree
?
?
?
?
?
?
The Assignment
A decision tree is a basic concept used in machine learning, using a dataset to determine future decisions.
What does it look like?
squash
orange
high carb
high fiber
likeToEat
true
decision tree
?
?
?
?
?
?
Decision Trees
An Example Dataset!
lowCarb
highFiber
likeToEat
color
name
spinach
kale
sweet potato
peas
eggplant
carrot
“green”
“green”
“orange”
“green”
“purple”
“orange”
true
true
true
false
true
true
false
true
true
true
true
false
false
true
true
false
true
false
An Example Dataset!
lowCarb
highFiber
likeToEat
color
name
spinach
kale
sweet potato
peas
eggplant
carrot
“green”
“green”
“orange”
“green”
“purple”
“orange”
true
true
true
false
true
true
false
true
true
true
true
false
false
true
true
false
true
false
An Example Decision Tree!
color
highFiber
lowCarb
highFiber
false
false
false
true
true
true
orange
purple
green
false
false
true
true
true
false
An Example Decision Tree!
color
Check the color attribute of the vegetable
An Example Decision Tree!
color
highFiber
lowCarb
true
If the color is “orange”, then check the highFiber attribute
If the color is “green”, then check the lowCarb attribute
If the color is “green”, then check the lowCarb attribute
If the color is “purple”, then this tree would return true!
orange
purple
green
An Example Decision Tree!
color
highFiber
lowCarb
highFiber
false
false
true
true
If highFiber is true, then this tree would return true!
If highFiber is false, then this tree would return false!
If lowCarb is false, then this tree would return false!
If lowCarb is true, then check the highFiber attribute
orange
purple
green
false
false
true
true
An Example Decision Tree!
color
highFiber
lowCarb
highFiber
false
false
false
true
true
true
orange
purple
green
false
false
true
true
true
false
If highFiber is true, then this tree would return true! Otherwise, this tree would return false!
Architecture
The Architecture Of Your Program!
Decision Tree (DecisionLeaf, ValueEdge, AttributeNode)
Dataset
TreeGenerator
A lot of this part of the project is up to you!
Building the Tree
lowCarb
highFiber
likeToEat
color
name
spinach
kale
sweet potato
peas
eggplant
carrot
“green”
“green”
“orange”
“green”
“purple”
“orange”
true
true
true
false
true
true
false
true
true
true
true
false
false
true
true
false
true
false
Let’s Look At The Data!
[spinach, kale, sweet potato, peas, eggplant, carrot]
Constructing a Tree!
lowCarb
highFiber
likeToEat
color
name
spinach
kale
sweet potato
peas
eggplant
carrot
“green”
“green”
“orange”
“green”
“purple”
“orange”
true
true
true
false
true
true
false
true
true
true
true
false
false
true
true
false
true
false
Let’s Look At The Data!
true
false
lowCarb
[spinach, kale, sweet potato, eggplant, carrot]
[peas]
Constructing a Tree!
Let’s Look At The Data!
lowCarb
highFiber
likeToEat
color
name
spinach
kale
sweet potato
peas
eggplant
carrot
“green”
“green”
“orange”
“green”
“purple”
“orange”
true
true
true
false
true
true
false
true
true
true
true
false
false
true
true
false
true
false
true
false
lowCarb
false
orange
purple
green
color
[sweet potato, carrot]
[spinach, kale]
[eggplant]
Constructing a Tree!
Let’s Look At The Data!
lowCarb
highFiber
likeToEat
color
name
spinach
kale
sweet potato
peas
eggplant
carrot
“green”
“green”
“orange”
“green”
“purple”
“orange”
true
true
true
false
true
true
false
true
true
true
true
false
false
true
true
false
true
false
true
false
lowCarb
false
orange
purple
green
color
[sweet potato]
false
false
true
true
true
highFiber
highFiber
[carrot]
[spinach]
[kale]
Constructing a Tree!
true
false
lowCarb
false
orange
purple
green
color
false
false
true
false
false
true
true
true
highFiber
highFiber
true
Constructing a Tree!
Design Check
Design Check Requirements
Finally, Check the handout for more info!
Roadmap
Getting Started
Questions?