Tag: Trees

  • ML0064 Random Forest II

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • ML0063 Random Forest

    How does the random forest algorithm operate? Please outline its key steps.

    Question card in three panels: a loan table of 1,000 customers with 20 features, a single fully grown decision tree scoring 100 percent on training data and 71 percent on test data, and two retrains after dropping 5 percent of rows that pick different root splits and give the same customer opposite decisions.

    The Problem: A bank’s single, fully grown decision tree scores 100% on training data but 71% on test data. Retraining it after dropping just 5% of rows changes its root split and flips the decision for the same customer. How does a random forest operate to turn this unstable learner into a reliable model, and what are its key steps?

    Answer

    Random Forest builds an ensemble of decision trees, each trained on a bootstrapped sample of the data with a random feature subset considered at each split. This combination reduces variance, combats overfitting, and improves predictive accuracy; the final output aggregates all trees’ predictions: majority vote for classification, averaging for regression.

    (1) Bootstrap Sampling: Create multiple subsets of the training data by sampling with replacement (bootstrap samples).
    (2) Grow Decision Trees: Train an unpruned decision tree on each bootstrap sample.
    (3) Random Feature Selection: At every split in every tree, consider only a random subset of features; this increases diversity between trees.
    (4) Aggregate: Classification: each tree votes for a class and the majority wins; regression: the tree outputs are averaged.

    Three individual tree decision boundaries with different jagged artifacts and the smoother random forest ensemble boundary

    Figure 1: Three trees, three different jagged boundaries: each overfits its own bootstrap sample in its own way. The ensemble’s boundary (bottom right) averages the votes and lands smoother and closer to the true structure: the trees’ individual errors cancel.

    Mathematical Formulation:
    \hat{y} = \mathrm{mode}\big\{ T_b(x) \big\},\quad b = 1, \ldots, B
    \hat{y} = \frac{1}{B} \sum_{b=1}^{B} T_b(x)

    Where:

    • T_b(x) is the prediction of the b-th tree for input x.
    • B is the total number of trees in the forest.
    • First line: classification by majority vote (mode); second line: regression by averaging.
    Flowchart from training data through bootstrap samples into three trees and a majority vote box producing the final prediction

    Figure 2: The full pipeline: B bootstrap replicas of the training set feed B independently grown trees (each with random feature subsets at its splits), and a majority-vote / averaging box fuses their outputs into one robust prediction.


    Login to view more content
  • ML0062 Decision Tree

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.