Decision Trees and Random Forests
- 55Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is a decision tree, and what is its basic purpose in machine learning?
55 questions
- 1
What is a decision tree, and what is its basic purpose in machine learning?
Model answer
A decision tree is a tree-like structure generated from data. It uses decisions based on feature values to classify an example or predict a target value.
Explanation
The tree starts at a root node and branches through decisions until it reaches an outcome.
- 2
Which types of machine learning problems can decision trees address?
Model answer
Decision trees can be used for classification and regression, including predicting target values or approximating a function.
Explanation
The tree’s final output can be either a class or a predicted value.
- 3
What is the difference between classification and regression?
Model answer
Classification assigns an example to one of a set of predefined classes, whereas regression predicts an output or target value.
Explanation
The distinction is the kind of result the model produces: a category or a value.
- 4
What does each node in a decision tree represent?
Model answer
Each node contains a collection of data points. A decision at a node can divide those points into smaller groups.
Explanation
The root initially contains all the data, while later nodes contain subsets created by earlier splits.
- 5
How does a decision tree make a prediction for a new example?
Model answer
It checks feature values at successive decision nodes and follows the corresponding branches until it reaches an outcome.
Explanation
The path through the tree ends at a node that supplies the predicted class or value.
- 6
Why are different algorithms and metrics available for constructing decision trees?
Model answer
Algorithms and metrics provide different procedures for choosing how data should be split as the tree is built.
Explanation
Software packages may offer these procedures as options, but they share the goal of constructing useful splits from data.
- 7
Which tree-building metrics are associated with classification, and which is associated with regression?
Model answer
Gini impurity and information entropy are typically used for classification; variance reduction is used for regression.
Explanation
The metrics assess splits in ways suited to the kind of target being modeled.
- 8
How does a decision tree resemble a sequence of human decisions?
Model answer
At each node, a feature-based condition determines which branch to follow, much like a sequence of “if this, then that” decisions.
Explanation
The sequence continues until the tree reaches a final decision.
- 9
What is the Iris classification problem described in the example?
Model answer
It is the task of classifying a new Iris flower as setosa, versicolor, or virginica using measured features.
Explanation
The example uses a known classification dataset to illustrate how a decision tree is built and used.
- 10
How many training examples of each species are used in the Iris example?
Model answer
The training data contain 49 setosa, 50 versicolor, and 50 virginica examples, for 149 examples in total.
Explanation
These class counts determine the class fractions at the root node.
- 11
Which four features are measured for each Iris flower in the example?
Model answer
The features are sepal length, sepal width, petal length, and petal width.
Explanation
A decision tree can use these measured geometric characteristics to make its splits.
- 12
What are the stated sepal-length ranges for the three Iris species?
Model answer
Setosa ranges from 4.3 to 5.8, versicolor from 4.9 to 7, and virginica from 4.9 to 7.9.
Explanation
These ranges are observations from the training data and illustrate how feature values may differ across classes.
- 13
What are the stated petal-length ranges for the three Iris species?
Model answer
Setosa ranges from 1 to 1.9, versicolor from 3 to 5.1, and virginica from 4.5 to 6.9.
Explanation
The overlap between the versicolor and virginica ranges contrasts with the separation between setosa and the other species.
- 14
Why are preclassified training examples needed for the Iris classification task?
Model answer
The training examples provide measured features paired with known species labels, allowing the algorithm to learn how to classify new flowers.
Explanation
Without labeled examples, the tree would not have the known class outcomes needed to learn classification rules.
- 15
What class would a root-only classifier predict in the Iris example, and why?
Model answer
It could predict either versicolor or virginica, since both have 50 examples and are tied for the largest class; the tie could be broken arbitrarily.
Explanation
The root contains all 149 examples, including 49 setosa, 50 versicolor, and 50 virginica.
- 16
If the root-only classifier always predicts versicolor, how many training examples does it classify correctly and incorrectly?
Model answer
It classifies 50 correctly and 99 incorrectly.
Explanation
Only the 50 versicolor examples match that prediction; the remaining 49 setosa and 50 virginica examples do not.
- 17
What is Gini impurity, and how is it calculated for a node with K classes?
Model answer
Gini impurity measures how mixed the classes are in a node and is calculated as 1−∑i=1Kfi2, where fi is the fraction of examples belonging to class i.
Explanation
The formula uses the class proportions among the examples currently at that node.
- 18
What class fractions are used to calculate the Gini impurity at the Iris root node?
Model answer
The fractions are 49/149 for setosa, 50/149 for versicolor, and 50/149 for virginica.
Explanation
Each fraction is the number of examples in one class divided by the 149 examples at the root.
- 19
What is the Gini impurity of a pure node, and why?
Model answer
A pure node has Gini impurity 0 because one class has fraction 1 and all other classes have fraction 0.
Explanation
Substituting those fractions into 1−∑ifi2 gives zero.
- 20
What does a pure node mean in classification?
Model answer
A pure node contains examples from only one class, with examples from the other classes absent.
Explanation
A prediction at such a node identifies the single class represented there.
- 21
How does Gini impurity generally change as a decision tree creates more homogeneous groups?
Model answer
It decreases as the groups become less mixed, reaching zero when a node is pure.
Explanation
Reducing impurity is the aim when seeking class-homogeneous leaf nodes.
- 22
For the Iris example, what is the Gini impurity of a node containing 50 versicolor examples and no other classes?
Model answer
It is 0, because the versicolor fraction is 1 and the other class fractions are 0.
Explanation
The class fractions are 50/50, 0/50, and 0/50.
- 23
What Gini impurity does a node with 50 versicolor and 50 virginica examples have?
Model answer
Its Gini impurity is 0.5, since the two class fractions are each 0.5 and the setosa fraction is 0.
Explanation
Applying the formula gives 1−02−0.52−0.52=0.5.
- 24
Why can the Gini impurity differ from one node to another?
Model answer
Each node can contain different numbers and proportions of the classes, so its class fractions—and therefore its Gini impurity—can differ.
Explanation
Every node’s impurity is calculated from the examples that reach that node.
- 25
What is a Gini split index, and how is it calculated for a two-child split?
Model answer
It is the parent node’s Gini impurity minus the weighted impurities of its children: Gparent−p1G1−p2G2, where p1 and p2 are the fractions of data sent to the children.
Explanation
The child impurities are weighted by the proportions of the parent’s examples they contain.
- 26
If a split sends 99 of 149 examples to one child and 50 to the other, what are the child weights in the Gini split calculation?
Model answer
The weights are 99/149 and 50/149.
Explanation
Each weight is the number of examples in a child divided by the total number in the parent.
- 27
What information is needed to evaluate a candidate decision-tree split using the Gini split index?
Model answer
You need the parent impurity, each child’s impurity, and the fraction of the parent’s examples sent to each child.
Explanation
These values determine the parent impurity reduction after weighting the child impurities.
- 28
Why does choosing a feature alone not fully specify a decision-tree split?
Model answer
A split also needs a threshold or other condition on that feature to determine which examples go to each child.
Explanation
For example, a tree might branch according to whether sepal length is below a chosen value.
- 29
How does a split using petal length below 2.4 partition the Iris training examples?
Model answer
It sends all 49 setosa examples to one child and the 50 versicolor plus 50 virginica examples to the other.
Explanation
The stated setosa petal-length range ends at 1.9, while the other species’ ranges begin at 3 or above.
- 30
What are the Gini impurities of the two children created by the petal-length split at 2.4?
Model answer
The child containing only setosa has impurity 0, and the child containing 50 versicolor and 50 virginica has impurity 0.5.
Explanation
The first child is pure; the second has equal proportions of two classes and no setosa examples.
- 31
What Gini split index does the example report for the petal-length threshold of 2.4?
Model answer
The reported Gini split index is approximately 0.324.
Explanation
It is calculated by subtracting the weighted child impurities from the root impurity; the pure child contributes zero impurity.
- 32
What class counts result from the example’s split on sepal length at 5.8?
Model answer
One child contains 49 setosa, 21 versicolor, and 3 virginica examples; the other contains 0 setosa, 29 versicolor, and 47 virginica examples.
Explanation
The split partitions the same 149 examples into two different groups from those produced by the petal-length split.
- 33
What Gini split index does the example report for the sepal-length threshold of 5.8?
Model answer
The reported Gini split index is approximately 0.1915.
Explanation
This is lower than the reported value for the petal-length split at 2.4.
- 34
How should a decision-tree algorithm choose among multiple candidate splits when using the Gini split index?
Model answer
It should choose the candidate with the maximum Gini split index.
Explanation
A larger index indicates a greater reduction in weighted impurity and children that are closer to pure.
- 35
Why is a high Gini split index preferred?
Model answer
A high index means the split reduces impurity substantially, moving the child nodes closer to pure groups.
Explanation
If both children were pure, their impurities would be zero and the split index would equal the parent impurity.
- 36
How can a tree continue growing after one branch has already become pure?
Model answer
The pure branch needs no further splitting, so the algorithm can continue exploring an impure branch.
Explanation
For example, after the petal-length split at 2.4 isolates setosa, the remaining versicolor–virginica branch can be split further.
- 37
What further split is used in the example to distinguish versicolor and virginica after the petal-length split?
Model answer
The example splits the remaining examples by petal width at 1.8: values below the threshold go to a versicolor-predicted node, and values above it go to a virginica-predicted node.
Explanation
The reported partition places 54 examples on one side and 46 on the other.
- 38
How does a decision tree assign a class label to a node that is not pure?
Model answer
It assigns the class that occurs most often among the examples in that node.
Explanation
This is the node’s most prevalent, or majority, class, even though some examples may belong to other classes.
- 39
How would the example tree classify a new Iris flower with petal length below 2.4?
Model answer
It would classify the flower as setosa.
Explanation
The petal-length branch below 2.4 leads to the node containing the setosa examples.
- 40
How would the example tree classify a new flower with petal length above 2.4 and petal width below 1.8?
Model answer
It would classify the flower as versicolor.
Explanation
The flower first follows the non-setosa branch, then the petal-width branch to the versicolor-predicted node.
- 41
How would the example tree classify a new flower with petal length above 2.4 and petal width above 1.8?
Model answer
It would classify the flower as virginica.
Explanation
The flower follows the non-setosa branch and then the petal-width branch to the virginica-predicted node.
- 42
Can a decision tree always produce perfectly pure nodes?
Model answer
No. Depending on the data, classes may overlap in feature values, making complete separation impossible.
Explanation
The tree’s attainable purity depends on whether the available features and their values can separate the classes.
- 43
Why can a tree that perfectly separates its training data perform poorly on new examples?
Model answer
It may overfit the training data, learning details that do not generalize to new examples.
Explanation
Perfect training-set separation does not guarantee that the learned decisions will work well beyond the training set.
- 44
Why might a tree deliberately stop growing before it eliminates every training error?
Model answer
Stopping can limit tree complexity and improve generalization, even if some training examples remain misclassified.
Explanation
A very deep tree may memorize the training set rather than learn patterns that hold for unseen data.
- 45
How can a model’s classification errors be assessed on data not used to build the tree?
Model answer
Use test data to check how often the tree’s predictions match the correct classes.
Explanation
A held-out test set provides a way to assess performance on examples beyond the training data.
- 46
What simple baseline prediction could be used for a regression problem before constructing a tree, and why might it be inadequate?
Model answer
One could predict the average target value of all training examples, but this may be a poor model because it ignores useful structure in the data.
Explanation
A regression tree can split the data into groups to make more informative predictions.
- 47
Why can a decision tree be sensitive to small changes or errors in its data?
Model answer
Small data changes can affect the selected thresholds and partitions, sometimes producing a substantially different tree.
Explanation
A tree’s decisions depend on particular feature-based splits, which may shift when the data change.
- 48
What is a random forest?
Model answer
A random forest is a collection of decision trees whose predictions are combined to produce a final prediction.
Explanation
The trees are built from different versions or subsets of the original data.
- 49
How can multiple training datasets be generated from one original dataset for a random forest?
Model answer
Create variations by selecting different subsets of data points, different subsets of features, or both.
Explanation
Each generated dataset is a modified portion of the original data.
- 50
How are the trees in a random forest constructed from the generated datasets?
Model answer
A decision tree is built for each generated dataset; for example, ten datasets can be used to build ten trees.
Explanation
Each tree learns from its own version of the original data.
- 51
How does a random forest combine classification predictions from its trees?
Model answer
It uses majority voting: the class predicted by the most trees becomes the forest’s prediction.
Explanation
For instance, if two trees predict setosa and one predicts virginica, the forest predicts setosa.
- 52
What must a random forest do if its trees split their votes equally among classes?
Model answer
It must break the tie using some decision rule to produce a final prediction.
Explanation
A tied vote does not identify a single majority class.
- 53
How does a feature-subset tree make a prediction when the full feature set is available for a new example?
Model answer
It uses only the features included when that tree was built.
Explanation
For example, a tree trained with sepal length and petal length uses those attributes to follow its decision rules.
- 54
Why can combining many trees make a random forest more robust than relying on one tree?
Model answer
Different trees reflect different subsets of the data or features, so the combined vote is less dependent on the fluctuations affecting any single tree.
Explanation
A result supported by many trees is less vulnerable to one tree’s particular errors or instability.
- 55
How does random forest voting address instability caused by variations in data?
Model answer
It combines predictions from trees trained on different data subsets or feature subsets, reducing reliance on any one potentially unstable tree.
Explanation
This ensemble approach is intended to provide greater robustness to data fluctuations.

Ask anything
We've read this whole study set, so questions about it get the best answers.