2.3.3 · D1Tree-Based & Instance Methods

Foundations — Gini impurity

1,781 words8 min readBack to topic

This page assumes you know nothing. Before you can read the parent note's formula , you must first know what a proportion is, what that stretched-out S () means, why we square, and what a "node" even looks like. We build every one of those, in order, with pictures.


0. The picture the whole topic lives in

Everything in this topic is about sorting things into boxes. Look at the figure: a big box of mixed circles gets split into two smaller boxes. Each box is a node.

We need this word because Gini impurity is always computed for one node at a time. There is no "Gini of the whole tree" — only the Gini of each box.


1. Counting: and

Before proportions, we must count.

Why the topic needs it: when we compare splits, a big child and a tiny child should not count equally. Counting lets us weight them (Section 6).


2. Class and proportion: , , and

The circles come in colors. In machine learning a "color" is called a class — the label we're trying to predict (apple/orange, spam/not-spam, +/−).

Now the star symbol of the whole topic:

Two facts about proportions that we'll lean on:

  • Every is between and (you can't have a negative share or more than 100%).
  • They all add up to 1, because every item belongs to exactly one class. This is written — which needs the next symbol.

3. The summation sign

This stretched letter scares beginners. It is just "add up a list."

Why the topic needs it: the Gini formula must combine all the classes into one number. is the tool that says "loop over every class and total it up."


4. Squaring: and why we square

Look at the curve in the figure: plotting against bends downward. A big share (say ) barely shrinks (); a small share () collapses ().


5. Putting it together: reading

You now own every symbol. Read the parent's formula left to right:

Quick sanity checks (all cases):

  • All one class: , , so . Pure box → never wrong. ✔
  • Fifty-fifty (2 classes): , , . Worst 2-class mix. ✔
  • Equal thirds (3 classes): , . Worst 3-class mix. ✔

6. Weighting a split:

A split makes several children. To score it we need one number, so we average the children's Ginis — but weighted by how many items each holds.

The tree then picks the split with the smallest , i.e. the biggest Gini gain .


Prerequisite map

Counting items N and Nc

Classes and index i up to K

Proportion pi equals count over N

Summation sign adds a list

Squaring pi rewards dominance

Gini G equals 1 minus sum of squares

Weighted split Gini

Decision Tree picks best split


Equipment checklist

Test yourself — reveal only after you've answered aloud.

What is a "node" in a decision tree?
A group of data items (a box); the root is the whole dataset, children are the smaller boxes after a split, a leaf is a box we stop splitting.
What does mean, and ?
= total items in the node; = number of items in child node .
What is a class, and what is ?
A class is a category/label an item can have; is how many distinct classes exist in the node.
What does the index do?
It's a counter that walks through the classes — a placeholder meaning "for each class".
Define the proportion in words and formula.
The fraction of the node's items in class : .
Why must ?
Every item belongs to exactly one class, so the shares fill the whole pie.
What does tell you to do?
Compute the expression for up to and add all results together.
What is probabilistically?
The chance two independent random grabs both land on class .
Why do we square instead of just using ?
Squaring rewards dominance — one big share makes large (pure, low ); an even spread makes it small (mixed, high ).
Why do we weight children by in a split?
So the score reflects total expected mistakes per item across the whole parent, not letting a tiny child count as much as a big one.

Connections