Quiz: decision trees

Short questions to test your understanding. Try each on paper first, then open the answer.


Q1. A tree has three questions: “x \le 0.5?”, then on both sides “y \le 0.3?”. Into how many regions does it cut the plane, and what shape are they?

Each question cuts one region in two, along an axis.

Four regions (one per leaf), all axis-aligned rectangles: left-bottom, left-top, right-bottom, right-top. Here both sides happen to use the same threshold on y, so the four rectangles form a 2 \times 2 grid.


Q2. A node holds 6 nuclei and 2 background pixels. What is its Gini impurity? What would a pure node have?

G = 1 - \sum_k p_k^2.

G = 1 - 0.75^2 - 0.25^2 = 0.375. A pure node (one class only) has G = 0; the most mixed two-class node has G = 0.5.


Q3. Why does the split search only try thresholds between neighbouring values of a feature?

What changes when the threshold moves between two neighbouring values?

Moving the threshold between two neighbouring values does not move any training point from one side to the other, so the split and its impurity stay the same. Only n - 1 distinct splits exist per feature for n distinct values; taking the midpoint is a convention.


Q4. A tree grown until every leaf is pure has 0 % training error. Why is that not good news?

What does it do with a mislabelled or noisy training point?

It has memorised the training data, including its noise: every mislabelled point gets its own small region. On new data those regions are wrong, so the test error is higher than for a shallower tree. Zero training error says nothing about new data.


Q5. You tried ten depths and chose the one with the smallest test error. What is wrong with reporting that test error?

What role did the test set play in the choice?

The test set was used to choose a setting, so it has become a validation set and its error is optimistic (the best of ten noisy numbers). Choose on a validation set or by cross-validation, then evaluate once on a test set that played no role in any choice.


Q6. In 5-fold cross-validation, how often is each training example used for validation, and how many trees are grown per setting?

Each fold takes its turn.

Each example is validated exactly once (when its fold is held out) and used for training in the other 4 rounds. Five trees are grown per setting, one per round; their 5 validation errors are averaged.


Q7. One feature is an area in µm², another an intensity from 0 to 4095. Do you have to rescale them before growing a tree?

Does a split depend on the size of the numbers or on their order?

No. A split only depends on the order of the values along one feature; rescaling (or any increasing transformation) moves the thresholds but keeps the same splits. Methods based on distances (nearest neighbour, the SVM) do need comparable scales.


Q8. A regression tree with 4 leaves is fitted to a smooth intensity ramp. What does the fit look like?

What does a leaf predict?

A staircase of 4 flat steps: each leaf predicts the mean of its points, so the fit is piecewise constant. A smooth ramp needs many leaves to be approximated well.


Q9. (math) Show that for two classes the Gini impurity is 2p(1-p), where p is the share of one class.

p_1 = p, p_2 = 1 - p.

G = 1 - p^2 - (1-p)^2 = 1 - p^2 - 1 + 2p - p^2 = 2p - 2p^2 = 2p(1-p). Equivalently \sum_{k \ne l}p_kp_l = p(1-p) + (1-p)p.