A random forest consists of a collection of decision trees,
each of which works like a rule-based predictor.
Decision trees predict the label or value, e.g. edible or not,
of a new datapoint based on its features.
Here, we use decision trees to predict whether or not the new mushroom will be poisonous
based on its 22 features, e.g. mushroom cap shape and color.
To train a decision tree, we give it many examples.
In the mushroom problem, the model uses the dataset of 8000 mushrooms
to find out a sequence of test of features that will best separate
edible mushrooms from poisonous ones.
Say the most telling feature of all is whether or not a
mushroom's stalk is smooth. In other words, this feature is the best one
for predicting if a mushroom is poisonous or not. Then the decision
tree applies this smoothness feature first. Then for each of the two outcomes,
i.e. smooth or not smooth, the decision tree looks for the
next best differentiating feature respectively.
It keeps doing this iteratively, and only stops
either when all the mushrooms left have the same value,
e.g. all edible or poisonous,
or when it hits some predetermined stop criteria.
The final structure of a trained decision tree looks like a flowchart.
It asks a single question about the test item,
moves onto the next question based on the answer,
and then asks more questions until it reaches a conclusion.
Check one out below! Hover over the highlighted circles to
see more details about the different components of a decision tree.
If you want to know more, check out
R2D3's Intro to Decision Trees.