2.3.7 · D1Tree-Based & Instance Methods

Foundations — Random forest algorithm

1,952 words9 min readBack to topic

This page assumes you know nothing. Before you can read the parent note's variance formula or its OOB derivation, you must own every letter, ratio, and squiggle it throws at you. We build them one at a time, each on top of the last.


0. The characters in this story (a first look)

Every symbol below will reappear in the parent note. Meet them once here so nothing is a surprise.

Symbol Plain words Lives where
how many rows (examples) we have the data table's height
how many features (columns/clues) each example has the data table's width
the -th example's clues one row
the -th example's true answer/label one cell
how many trees in the forest count of learners
the prediction of tree number one tree's output
the average of all tree predictions the forest's final answer
how spread out one tree's predictions are "moodiness" of a tree
how alike two trees' answers are (correlation) agreement between trees
how many features a tree may peek at per split a small piece of

We now earn each of these, in order.


1. Data as a table: , , rows and columns

Picture a spreadsheet. Every row is one example (one animal, one house, one patient). Every column is one feature — a measured clue about that example.

Figure — Random forest algorithm
  • (read "x sub i") means: take row number — all its clues bundled together. The little underneath is just an address label ("which row"), like a seat number.
  • (read "y sub i") means: the true answer sitting in row .

2. A decision tree: the single "moody expert"

Before a forest you need one tree. A decision tree is a flowchart of yes/no questions. Each question splits the examples into two groups; you keep asking until a group is pure enough to guess a label.

Figure — Random forest algorithm

The tree chooses each question to make the two resulting groups as pure as possible (mostly one label). "Purity" is measured by Gini impurity or entropy — you don't need the formula here, only the idea: a good split separates the classes.


3. Prediction, and why one tree is "high variance"

Run a tree on a new example ; it walks the flowchart and lands in a leaf. That leaf's guess is the prediction, written — "the answer of tree for input ."

Now the key personality trait: variance.

Figure — Random forest algorithm

4. Averaging: and the summation symbol

The forest's answer is the average of all its trees. Two pieces of notation carry this.


5. Correlation : how alike two trees are

Averaging only helps if the trees disagree in their mistakes. If every tree makes the same error, averaging their identical wrong answers still gives that wrong answer. We measure "sameness of answers" with correlation.

Figure — Random forest algorithm

6. Bootstrap sampling: , "with replacement", and

Two last tools power the randomness.

Bootstrap sample — draw rows from your rows with replacement: after picking a row you put it back, so it can be picked again. Some rows appear twice, some not at all.

out of features — at each split a tree may only look at a random handful of the features. Typical . This forces trees onto different clues → lowers .

The expression — this shows up in the OOB derivation. Read it as: one draw misses a fixed row with chance ; do that independent times → multiply → . As grows this settles onto a famous number:


The prerequisite map

Data table: n rows, p features

Decision tree: splits and leaves

Prediction f_b and its variance sigma squared

Averaging: bar f and the sum sign

Bootstrap rows: sample with replacement

Random m features per split

Correlation rho between trees

Random Forest

Read top to bottom: the table feeds the tree; the tree gives predictions with variance; averaging pools them; bootstrap and feature-subsetting control correlation; all of it converges on the forest.


Equipment checklist

Self-test: cover the right side, answer, then reveal.

What does count, and where do you see it in the table?
The number of examples (rows) — the table's height.
What does count?
The number of features (columns/clues) — the table's width.
Read and in words.
Row 's clues, and row 's true label.
What is a split in a decision tree?
A yes/no question that cuts the examples into two more-pure groups.
What does variance measure for a tree?
How much its answer scatters when the training data changes slightly (its moodiness).
Why do we square the gap from the mean in variance?
So too-high and too-low errors both count as positive and don't cancel.
Expand .
.
What does the bar in mean?
The average of all tree predictions (the forest's output).
What does mean for two trees, and why is it bad?
They are clones that always agree; averaging clones removes no error.
What does "with replacement" mean?
A drawn row goes back in the bag and can be drawn again.
What is ?
The small random subset of features a tree may consider at each split.
What number does approach, and to what value?
.

Connections