Sample questions
Question 1Easy
Which is a common way to prevent a decision tree from overfitting?
- Growing the tree until every leaf is pure
- Using every feature at every split
- Removing the root node after training so that the tree has fewer levels
- Limiting the maximum depth or pruning the tree
Answer: D. Limiting the maximum depth or pruning the tree
Explanation
Constraints such as max_depth, min_samples_leaf, or cost-complexity pruning stop the tree from memorising noise.
Step-by-step solution
- An unrestricted tree keeps splitting until leaves are pure.
- That memorises noise in the training data.
- Limiting depth, requiring a minimum number of samples per leaf, or pruning keeps it simpler.
Why the other options are wrong
- A. Growing to pure leaves is what causes overfitting.
- B. Using every feature does not limit complexity.
- C. Removing the root destroys the tree; it is not a valid technique.
Question 2Easy
What is the entropy of a node containing 50% positive and 50% negative examples (log base 2)?
- 2
- 1
- 0.5
- 0
Answer: B. 1
Explanation
Entropy = -0.5 log2 0.5 - 0.5 log2 0.5 =
0.5 + 0.5 = 1, the maximum for two classes. A pure node has entropy 0.
Step-by-step solution
- Entropy H = -sum p log2 p.
- p = 0.5 for each class: H = -(0.5 x -1 + 0.5 x -1).
- H = 1 bit.
Why the other options are wrong
- A. Two-class entropy is at most 1 bit.
- C. 0.5 is the maximum Gini impurity, not entropy.
- D. Entropy is 0 only for a pure node.
Tip: Two classes: 50/50 gives entropy 1 and Gini 0.5.
Question 3Medium
A node has 4 samples: 1 of class A and 3 of class B. What is its Gini impurity?
- 0.25
- 0.375
- 0.75
- 0.5
Answer: B. 0.375
Explanation
Gini = 1 - (p_A^2 + p_B^2) = 1 - (0.25^2 + 0.75^2) =
1 - (0.0625 + 0.5625) = 0.375.
Step-by-step solution
- Gini = 1 - sum of p squared.
- p(A) = 1/4, p(B) = 3/4.
- Gini = 1 - (1/16 + 9/16) =
6/16 = 0.375.
Why the other options are wrong
- A. 0.25 is p(A), not the impurity.
- C. 0.75 is p(B).
- D. 0.5 is the Gini of a 50/50 node.
Tip: Two classes: Gini = 2p(1 - p) = 2 x 0.25 x 0.75 = 0.375.
Question 4Medium
How does boosting (e.g. AdaBoost or gradient boosting) differ from bagging?
- It uses only one model
- Models are trained independently in parallel on bootstrap samples
- Models are trained in sequence, each fixing earlier errors
- It always uses neural networks as base learners
Answer: C. Models are trained in sequence, each fixing earlier errors
Explanation
Boosting mainly reduces bias by adding weak learners that correct residual errors; bagging mainly reduces variance.
Step-by-step solution
- Bagging trains models independently, in parallel, on bootstrap samples.
- Boosting trains models one after another.
- Each new model focuses on the errors of the ones before it.
Why the other options are wrong
- A. Both are ensembles of many models.
- B. This describes bagging, not boosting.
- D. Boosting usually uses small decision trees, not neural networks.
Tip: Bagging = parallel + average; boosting = sequential + correct.
Question 5Medium
Random Forest reduces overfitting compared with a single decision tree mainly by:
- Training trees sequentially on previous errors
- Pruning every tree to depth 1 so that each one is too simple to overfit
- Using only linear decision boundaries
- Averaging many trees built on bootstrap samples and random features
Answer: D. Averaging many trees built on bootstrap samples and random features
Explanation
Bagging plus random feature selection decorrelates the trees, so averaging them reduces variance.
Step-by-step solution
- Each tree trains on a bootstrap sample (rows drawn with replacement).
- Each split considers only a random subset of features.
- Averaging many decorrelated trees cancels out their individual errors and lowers variance.
Why the other options are wrong
- A. Sequential training on errors is boosting.
- B. Random forests usually grow deep trees, not stumps.
- C. Trees give axis-aligned, non-linear boundaries.
Question 6Medium
Which statement about decision trees is true?
- They do not require feature scaling
- They cannot handle categorical features in principle
- They always produce linear decision boundaries
- They can only be used for classification
Answer: A. They do not require feature scaling
Explanation
Splits compare a single feature with a threshold, so rescaling a feature does not change the tree. Trees also do regression (CART) and give axis-aligned, non-linear boundaries.
Step-by-step solution
- Trees split on thresholds such as 'age > 30'.
- Rescaling a feature changes the threshold value but not which rows go left or right.
- So scaling does not affect a tree.
Why the other options are wrong
- B. Trees can split on categories directly in principle.
- C. Tree boundaries are piecewise, axis-aligned and non-linear.
- D. Regression trees predict numbers too.
Tip: Trees and forests: no scaling needed.
Question 7Hard
In a Random Forest, what is the out-of-bag (OOB) error?
- Error on a separate test set supplied by the user
- Error on training rows left out of each tree's bootstrap sample
- Training error of the deepest tree in the forest, measured on its own bootstrap sample
- Error caused by features missing from the dataset
Answer: B. Error on training rows left out of each tree's bootstrap sample
Explanation
Each bootstrap sample leaves out about 37% of the rows; predicting them with the trees that did not see them gives a built-in validation estimate.
Step-by-step solution
- Each bootstrap sample leaves out about a third of the rows.
- Those out-of-bag rows are predicted only by trees that did not see them.
- The error on these predictions estimates test error without a separate set.
Why the other options are wrong
- A. OOB error needs no user-supplied test set.
- C. A tree's error on its own bootstrap sample is training error.
- D. OOB has nothing to do with missing features.
Tip: OOB is about 37% of rows per tree: a built-in validation set.
Question 8Hard
A node has 6 positive and 4 negative samples (entropy 0.971). A split produces a left child with 4 positive, 0 negative and a right child with 2 positive, 4 negative (entropy 0.918). What is the information gain of the split?
- 0.05
- 0.42
- 0.97
- 0.55
Answer: B. 0.42
Explanation
Weighted child entropy =
(4/10) x 0 + (6/10) x 0.918 = 0.551.
Information gain =
0.971 - 0.551 = 0.42.
Step-by-step solution
- Left child (4+, 0-) is pure: entropy 0, weight 4/10.
- Right child (2+, 4-) has entropy 0.918, weight 6/10.
- Weighted child entropy = 0.6 x 0.918 = 0.551.
- Gain = 0.971 - 0.551 = 0.42.
Why the other options are wrong
- A. 0.05 comes from subtracting the unweighted right entropy (0.971 - 0.918).
- C. 0.97 is the parent entropy, not the gain.
- D. 0.55 is the weighted child entropy, not the gain.
Practise all 8 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →