2.3.8 · D1Tree-Based & Instance Methods

Foundations — Feature importance from trees

2,028 words9 min readBack to topic

This page builds every symbol the parent note Feature importance from trees throws at you, starting from absolute zero. If the parent wrote and you froze — this page unfreezes you, one symbol at a time.


0. The picture behind everything: a tree sorting marbles

Before any symbol, hold this picture in your head.

Figure — Feature importance from trees

Look at the figure. At the top is a box holding a mix of coral and mint marbles — messy. We ask a question ("is the marble bigger than a coin?"), and it splits the box into two smaller boxes below. Each smaller box is (hopefully) less mixed — more of one colour. Every circle here is called a node. The top node is the root, the boxes below are its children.

That's the whole game. Everything else is just notation for "how messy", "how much less messy", and "how much data was affected".


1. The data: samples, , and features

Why the topic needs these. Later we weight a question by "how many marbles it touched", which is exactly out of . So and are the raw counts that make weighting possible.


2. The subscript language: , ,

The little letters attached to and are just labels for which box we mean.

Figure — Feature importance from trees

Read the figure: one parent box with marbles pours into a left box (holding ) and a right box (holding ). Every marble goes to exactly one side, so the counts always add up:


3. Proportions: and

The parent note writes . Two new symbols: and .

Why the topic needs this. "Messiness" (impurity) will be built entirely out of these proportions — a box that is all one colour has one and the rest ; a box that is evenly split has small everywhere. The sum-of-squares captures that difference.


4. Impurity — putting a number on "messy"

Now we can define the star symbol: , read "the impurity of node ."

Figure — Feature importance from trees

The figure shows three boxes and their Gini impurity :

  • All coral → (pure, floor value).
  • 3 coral / 1 mint → .
  • Even 2 / 2 → (the maximum mess for two colours).

For number columns (regression) the messiness meter is variance — how spread out the numbers are around their average. Same idea, different flavour; the parent uses there.


5. The average bar:

The regression formula uses .


6. Impurity decrease — the payoff of a question

This is the heart of the topic. New symbol: (Greek capital delta).

WHAT we just did: subtracted the children's messiness from the parent's messiness. WHY the fractions : they are the shares of marbles going left and right. A child holding more marbles should count more toward the "after" mess — so we weight each child's impurity by its share. These two fractions add to , so the bracket is a genuine weighted average. WHAT IT LOOKS LIKE: the tall parent bar shrinking down to two shorter child bars in the figure below.

Figure — Feature importance from trees

In the figure, the coral bar (parent impurity ) is the "before". The two mint bars are the children; their sample-weighted average is the "after" line. The green gap between them is — the cleanup earned by this one question.


7. The arrival weight

We now know a question's local payoff . But a question near the root touches everyone; a question deep down touches a handful. To be fair we scale by how much of all the data reached that node.


8. Assembling the parent's formula

Now every piece of is de-mystified:

Symbol Plain words Picture
importance of feature total points feature scored
add over every node that asked about walk the tree, collect 's boxes
slice of all data reaching that box pie fraction
cleanup at that box shrinking-bar gap

For a whole forest you just average over all trees and normalize so the importances sum to . That normalization, biases, and better alternatives (Permutation Importance, SHAP Values) are the parent note's job — you now have the vocabulary to read it.


9. Prerequisite map

Samples and counts N Nt

Proportions pk and sum

Impurity i of t

Mean y bar for regression

Impurity decrease delta i

Arrival weight Nt over N

Feature importance MDI

Read it bottom-up: counts and proportions build impurity; impurity builds decrease; decrease plus weight builds importance.


Equipment checklist

Cover the right side and answer before revealing.

What is versus ?
= total samples in the whole dataset (fixed); = samples that reach node (shrinks with depth).
What do , , label?
A node (parent) and its left and right child boxes — subscripts are name tags, not multiplication.
What is and what range does it live in?
The fraction of samples in a box that are class ; between 0 and 1, and all in a box sum to 1.
What does compute?
Add up the square of each class proportion — the probability two random draws match colour.
What does mean?
The box is perfectly pure — all one class, nothing left to clean.
What does the symbol mean in ?
"Change/drop" — impurity before the split minus the weighted impurity after.
Why are children weighted by and ?
Bigger children hold more samples and should count more; the two fractions form a weighted average that sums to 1.
Why is ?
The greedy tree only accepts splits that reduce impurity, and impurity is concave, so splitting can't increase weighted messiness.
What is the arrival weight and its value at the root?
The fraction of the whole dataset reaching node ; at the root it equals 1.
How do you get forest importance from tree importances?
Average the per-tree importances across all trees, then normalize to sum to 1.