ML0062 Decision Tree

Please explain how a decision tree works.

Answer

A decision tree partitions the input space into regions by recursively splitting on the feature that best separates the target variable. Each split aims to improve the “purity” of the resulting subsets, measured by criteria such as Gini impurity or entropy. Predictions follow the sequence of splits down to a leaf, returning the most common class (classification) or the average target (regression).

(1) Structure: A tree of nodes: internal nodes test a feature, branches represent the outcomes, leaves give predictions.
(2) Splitting Criterion: Choose the best feature and threshold by maximizing purity: information gain (entropy), Gini impurity, or variance reduction for regression.
(3) Recursive Growth: Starting at the root, split the data, then recurse on each subset until stopping criteria are met (max depth, min samples, or pure leaves).
(4) Prediction: A new sample travels from root to leaf following the feature tests; the leaf’s label or value is returned.

Left panel 2-D data partitioned by axis aligned decision regions, right panel the corresponding tree with gini and sample counts at each node

Figure 1: A decision tree from two viewpoints: on the left, the axis-aligned rectangular regions it carves into the feature space; on the right, the tree itself: each node shows its test, impurity, and class counts, and each leaf is a final answer.

Mathematical Formulation:
\mathrm{Gini}(t) = 1 - \sum_{k=1}^{K} p_k^2
\mathrm{Entropy}(t) = -\sum_{k=1}^{K} p_k \log_2(p_k)
\mathrm{Information\ Gain} = \mathrm{Entropy}(\mathrm{Parent}) - \sum_{i} \frac{N_i}{N} \, \mathrm{Entropy}(\mathrm{Child}_i)

Where:

  • t is a tree node; K the number of classes; p_k the proportion of class k samples in node t.
  • Gini = 0 means the node is pure (one class only) and grows with mixing; entropy = 0 at perfect purity and is maximal when classes are uniformly mixed.
  • In the gain formula, N is the parent’s sample count and N_i child i‘s: the split chosen is the one maximizing this weighted impurity drop.
Gini and entropy impurity curves versus class probability both peaking at one half and zero at the extremes

Figure 2: The two classification criteria compared for a binary node: both peak at p = 0.5 (maximally mixed) and vanish at pure nodes; they nearly always rank candidate splits in the same order, which is why Gini (no logarithms) is the common default.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *