information and entropy
learning from examples
what it is
How mixed a group is can be counted, and so can how much a question tells you about it. This page counts both, first on 8 points and then on a school's students.
Take the 8 points drawn below, 5 triangles and 3 squares. Pick one without looking, and 5 times in 8 it is a triangle. The group is mixed, but not evenly.
Say you must find one of 8 things by yes-or-no questions, each halving what is left: 8, then 4, then 2, then 1. That takes 3 questions. The log to base 2 of 8 is 3, the power 2 is raised to, to make 8. So a thing that is 1 in 8 of the group takes the log of 8, the log of one over its share, to single out.
Entropy averages that count over the group: each shape's share times the log of one over its share, added. The table works it for the 5 triangles and 3 squares: 5/8 × 0.678 + 3/8 × 1.415, about 0.954. A shape with no points adds nothing, as it never turns up.
| shape | share | one over the share | log to base 2 | share × log |
|---|---|---|---|---|
| triangles | 5/8 | 8/5 | 0.678 | 0.4238 |
| squares | 3/8 | 8/3 | 1.415 | 0.5306 |
| added | 0.9544 |
A group of one shape has entropy 0: its share is 1, and the log of 1 is 0, so no question is needed. Half and half is 1/2 × 1 + 1/2 × 1 = 1, as the log to base 2 of 2 is 1. The curve, drawn at every share, is highest there. The slider below moves between them.
4 triangles and 4 squares: an entropy of 1.
With scripts on, a slider sets how many of the 8 are triangles. The bars, the point and this line change with it.
A question splits the group in two. Across 0 to 3? asks whether a point stands between 0 and 3 along the bottom. It puts 4 triangles on one side, one shape, entropy 0. The other side has 1 triangle and 3 squares: 1/4 × 2 + 3/4 × 0.415 = 0.811. One over 1/4 is 4, whose log is 2, and one over 3/4 is 4/3, whose log is about 0.415. A question's gain is the group's entropy minus each side's entropy times its share of the group: 0.954 − (4/8 × 0 + 4/8 × 0.811) = 0.549. The information a question gives is its gain.
| question | gain |
|---|---|
| across 0 to 3? | 0.549 |
| up 7 to 10? | 0.049 |
| across 0 to 1? | 0.092 |
The question gains 0.549.
With scripts on, a picker shows each question's two sides. The drawing and this line change with it.
Up 7 to 10? leaves 2 triangles and 2 squares on one side, entropy 1, and 3 triangles and 1 square on the other, 0.811. It gains 0.954 − (4/8 × 1 + 4/8 × 0.811) = 0.049, far less.
A decision tree that measures how mixed a group is this way, as this site's does, weighs every question and asks the one that gains most. It then does the same inside each side. It stops when a group is one shape, when it has asked as many questions in a row as it is allowed, or when no question gains. Some trees measure how mixed a group is in another way.
where the formulas come from
Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about , or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.
the move: each share times the log of one over it
the line:why it is allowed: is the entropy of triangles and squares. Each shape's share is of the points, and one over it is over .
the move: cancel the n
the line:why it is allowed: By line 1, over is a half, and over is 2.
guess it, thenthe move: two halves make one
the line:why it is allowed: By line 2, half of a number added to half of it is the number.
guess it, thenthe move: read the log
the line:why it is allowed: By line 3, 2 is 2 to the power 1, so its log to base 2 is 1. For 4 triangles and 4 squares, 1.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
a worked example
A school asks 12 students how they come in. 9 walk and 3 ride. Which question tells more about who rides, does a student live within 2 km, or does a student have a brother or sister at the school?
- The group: the walkers' share is 9/12 and the riders' 3/12, so its entropy is 9/12 × 0.415 + 3/12 × 2, about 0.811.
- Within 2 km? 9 say yes, 8 walkers and 1 rider, entropy 8/9 × 0.170 + 1/9 × 3.170, about 0.503. 3 say no, 1 walker and 2 riders, entropy 0.918. The gain is 0.811 − (9/12 × 0.503 + 3/12 × 0.918) = 0.204.
- A brother or sister at the school? 7 say yes, 5 walkers and 2 riders, entropy 0.863. 5 say no, 4 walkers and 1 rider, entropy 0.722. The gain is 0.811 − (7/12 × 0.863 + 5/12 × 0.722) = 0.007.
- Living within 2 km tells far more, so a decision tree would ask it first.
| question | gain |
|---|---|
| within 2 km? | 0.204 |
| a brother or sister here? | 0.007 |
The question gains 0.204.
With scripts on, a picker shows each question's two sides. The drawing and this line change with it.
the trap
check yourself
A group holds 6 triangles and no squares. What is its entropy?
the answer
0. Every point is one shape, so nothing is mixed.
A group holds 4 triangles and 4 squares. What is its entropy?
the answer
1. Half and half is the top of the curve.
A question splits 5 triangles and 5 squares into two sides, 3 triangles and 3 squares, and 2 triangles and 2 squares. What does it gain?
the answer
0. Each side is half and half, entropy 1, as mixed as the group, so nothing is gained.