Skip to content

decision tree

learning

Level 2 of 3

Also called a classification tree.

test yourself

Six questions, four to pick from and two for paper. A point such as 1 2 t is a triangle at 1 across, 2 up (s is a square). After the semicolon comes the greatest depth. Each answer stays hidden until you open it.

fresh numbers: the questions a run answers, asked again on new numbers

choose one

question 1

Points 1 2 t, 2 6 t, 5 1 s, 6 7 s, 8 3 s and 9 9 s, grown at most 2 deep. How many looks in all, each question reading each point of its group once?

02468100246810A2+4
the answer, and why

the answer is B

The 6 points stand at 6 places across and 6 up, so 5 + 5 = 10 questions, each reading 6 points. Across below 3.5 leaves two groups of one shape, so no other group is weighed: 10 × 6 = 60 looks.

if you chose another

  • That counts the questions, not the points each reads.
  • That counts each point once.
  • That counts only the 5 questions across.

question 2

On the same points, what does across below 3.5 gain?

02468100246810A2+4
the answer, and why

the answer is B

The group, 2 triangles and 4 squares, has entropy 2/6 × 1.585 + 4/6 × 0.585, about 0.918. 1.585 is the log to base 2 of 6/2, and 0.585 of 6/4. Both sides are one shape, entropy 0, so the gain is all of it.

this tests how it works, on the learn page

if you chose another

  • That is the gain of a perfect question on half and half; this group is 2 and 4.
  • That is the triangles' share alone, 2 of 6.
  • That would be a question leaving both sides as mixed as the group.

question 3

Four points 2 2 t, 2 8 s, 8 2 s and 8 8 t, the corners crossed, grown at most 3 deep. How many leaves does the tree have?

02468100246810A2+2
the answer, and why

the answer is D

Each question, across below 5 or up below 5, leaves 1 triangle and 1 square on each side, as mixed as the group. No question gains, so the root is a leaf.

if you chose another

  • That would need questions that gain; here none does.
  • That is the number of shapes, not of leaves.
  • That is the greatest depth, which the tree never reaches.

question 4

Which is true of a decision tree on n points?

the answer, and why

the answer is A

A question's gain needs each side's count of triangles and squares, so it reads every point of the group.

this tests best, worst and average, on the learn page

if you chose another

  • A tree stops once every group is one shape, however deep it may grow.
  • Each point is looked at once for each question its group weighs.
  • Where the points stand changes how many questions there are, not how far apart they are.

pen and paper

question 5about 12 minutes

Seven points, 2 1 t, 1 4 t, 3 6 t, 6 2 s, 7 5 s, 8 8 s and 9 3 s, grown at most 1 deep.

  1. List every question the root weighs.
  2. Work out the gain of across below 4.5, and say what each leaf becomes.
  3. Count the points looked at, and check them against the questions times nn.
a hint

The points stand at 7 places across and 7 up. The group is 3 triangles and 4 squares.

a worked answer

Across below 1.5, 2.5, 4.5, 6.5, 7.5 and 8.5; up below 1.5, 2.5, 3.5, 4.5, 5.5 and 7: 12 questions. Across below 4.5 leaves 3 triangles on one side and 4 squares on the other. So it gains the group's whole entropy, 3/7 × 1.222 + 4/7 × 0.807, about 0.985. 1.222 is the log to base 2 of 7/3, and 0.807 of 7/4. The left leaf is a triangle and the right a square. The run looks at 12 × 7 = 84 points.

this tests how it works, on the learn page

what a full answer includes
  • The 12 questions.
  • The gain of about 0.985, with the two leaves.
  • Eighty four looks matching 12 times 7.

question 6about 10 minutes

Take section 5's four points on the diagonal, 0 0 t, 1 1 s, 2 2 t and 3 3 s, grown at most 3 deep.

  1. How many questions does each group weigh, and how many points does each look at?
  2. Add the looks, and check them against 6n2−18n+166n^2 - 18n + 16.
  3. Grown at most 1 deep instead, how many looks?
a hint

Each question that gains most peels off one end point.

a worked answer

The root's 4 points weigh 6 questions, 24 looks. Then 3 points weigh 4, 12 looks, and 2 points weigh 2, 4 looks. The total is 40, and 6 × 16 - 18 × 4 + 16 is 40. Grown 1 deep, only the root is weighed: 24 looks.

Why does the diagonal by turns, grown 3 deep, look 6n2−18n+166n^2 - 18n + 16 times?
  1. the move: see the questions

    the line:
    m points, all apart:2(m−1) questions,each looks at m\begin{gathered} m \text{ points, all apart:} \\ 2(m - 1) \text{ questions,} \\ \text{each looks at } m \end{gathered}
    02468100246810A2+2B1+0C1+2D0+1E1+1FG

    why it is allowed: On the diagonal no two points share a place across or up. A group of mm points has m−1m - 1 gaps each way, so 2(m−1)2(m - 1) questions, and each looks at all mm points.

  2. the move: an end point peels off

    the line:
    m points→1 leaf+(m−1) points\begin{gathered} m \text{ points} \to \\ 1 \text{ leaf} + (m - 1) \text{ points} \end{gathered}
    pointsgain of each cut across, left to right
    30.252, 0.252
    40.311, 0, 0.311
    50.171, 0.020, 0.020, 0.171
    60.191, 0, 0.082, 0, 0.191
    Every cut's gain on the diagonal by turns. The two end cuts gain most, and up has the same cuts, so the first cut across is asked. The same holds at every size measured, 3 to 1,000.

    why it is allowed: On the diagonal by turns, the end cuts leave one point alone, of one shape, and gain most, as the table shows. A tie goes to the smaller cut. That point is a leaf and weighs nothing. What is left is again a diagonal by turns.

  3. the move: three groups weighed

    the line:
    C=2n(n−1)+2(n−1)(n−2)+2(n−2)(n−3)\begin{gathered} C = 2n(n - 1) \\ + 2(n - 1)(n - 2) \\ + 2(n - 2)(n - 3) \end{gathered}
    grouppointsquestionslooked
    the root4624
    after one end point leaves3412
    after another224
    The 4 points of section 5, grown 3 deep. Each question that gains most peels off one end point, a leaf of one shape. 24 + 12 + 4 = 40.

    why it is allowed: CC is the points looked at. By lines 1 and 2, the groups weighed hold nn, then n−1n - 1, then n−2n - 2 points. After 3 questions in a row the groups are leaves. At 3 points the third group holds 1 point and weighs nothing: 2 × 1 × 0 = 0. At 2 points the second group holds 1 point, 2 × 1 × 0 = 0, and the third holds none, 2 × 0 × (−1) = 0.

  4. the move: multiply out

    the line:
    C=(2n2−2n)+(2n2−6n+4)+(2n2−10n+12)\begin{gathered} C = (2n^2 - 2n) \\ + (2n^2 - 6n + 4) \\ + (2n^2 - 10n + 12) \end{gathered}

    why it is allowed: By line 3, each pair of brackets multiplied out.

  5. the move: add like terms

    the line:
    C=6n2−18n+16C = 6n^2 - 18n + 16

    why it is allowed: By line 4, the squares add to 6n26n^2, the nn terms to −18n-18n, and the numbers to 16. For 4 points, 40.

  6. the move: a ceiling

    the line:
    C≤6n2C \le 6n^2

    why it is allowed: By line 5, CC is 6n26n^2 with 18 times nn taken away and 16 put back. From 1 point on, more is taken away than put back.

  7. the move: read it as a bound

    the line:
    C∈O(n2)C \in O(n^2)

    why it is allowed: By line 6, CC is at most 6 times n2n^2.

  8. the move: drop the later groups

    the line:
    C≥2n(n−1)C \ge 2n(n - 1)

    why it is allowed: By line 3, the other two terms are never below 0 from 2 points on, so CC is at least its first term.

  9. the move: a floor

    the line:
    C≥n2C \ge n^2
    points2n(n−1)2n(n - 1)n2n^2
    244
    3129
    42416
    54025
    The first term against n2n^2. They meet at 2 points, and the first term pulls ahead from there.

    why it is allowed: By line 8. From 2 points on, n−1n - 1 is at least half of nn; times 2n2n, line 8's term is at least n2n^2, as the table shows.

  10. the move: read it as a bound

    the line:
    C∈Ω(n2)C \in \Omega(n^2)

    why it is allowed: By line 9, CC never drops below 1 times n2n^2.

  11. the move: ceiling and floor together

    the line:
    C∈Θ(n2)C \in \Theta(n^2)

    why it is allowed: Lines 7 and 10 bound CC by the same growth, n2n^2.

try it with a small nn: at n=4n = 4, line 3 gives C=40C = 40, which you can work out by hand

this tests where the formula comes from, on the learn page

what a full answer includes
  • The three groups and their questions.
  • Forty, matching the formula.
  • Twenty four at depth 1.