In this lesson, we’ll create a decision tree build off of a dataset about cars. When considering buying a car, what factors go into making that decision?
Each car can fall into four different classes which represent how satisfied someone would be with purchasing the car — unacc
(unacceptable), acc
(acceptable), good
, vgood
.
Each car has 6 features:
- The price of the car which can be
"vhigh"
,"high"
,"med"
, or"low"
. - The cost of maintaining the car which can be
"vhigh"
,"high"
,"med"
, or"low"
. - The number of doors which can be
"2"
,"3"
,"4"
,"5more"
. - The number of people the car can hold which can be
"2"
,"4"
, or"more"
. - The size of the trunk which can be
"small"
,"med"
, or"big"
. - The safety rating of the car which can be
"low"
,"med"
, or"high"
.
We’ve imported a dataset of cars behind the scenes and created a decision tree using that data. In this lesson, you’ll learn how to build that tree yourself, but for now, let’s see what the tree can do!
Instructions
Create a variable named car
. We’re going to be feeding car
into tree
, the decision tree we’ve made behind the scenes. car
should be a list of six items — one value for each feature.
Try to make is a car that you think would have the label vgood
and we’ll see if the decision tree agrees with you!
Make sure your features are in the order listed above.
Call classify()
using car
and tree
as parameters. Print the result.
Did the decision tree classify car
as you expected?
Feel free to change the features of car
to see how tree
reacts.