Search Knowledge

© 2026 LIBREUNI PROJECT

Machine Learning / Supervised Learning

Decision Trees

Decision Trees and the CART Algorithm

Decision Trees are non-parametric models that recursively partition the feature space, predicting targets using simple hierarchical decision rules.

Recursive Induction: The CART Algorithm

The CART algorithm builds binary trees by searching for a feature kk and threshold tkt_k that minimize the weighted impurity of child nodes.

J(k,tk)=mleftmIleft+mrightmIrightJ(k, t_k) = \frac{m_{\text{left}}}{m} I_{\text{left}} + \frac{m_{\text{right}}}{m} I_{\text{right}}

where II represents the impurity of a node, and mm is the number of samples.

Split Selection Logic

The CART algorithm is greedy: it searches for the best split at the current step rather than evaluating combinations globally. It does not guarantee finding the globally optimal tree.

Impurity Measures

  • Gini Impurity: Probability of a random element being misclassified. G=1i=1Cpi2G = 1 - \sum_{i=1}^{C} p_i^2
  • Entropy: Quantifies node disorder or uncertainty. H=i=1Cpilog2(pi)H = -\sum_{i=1}^{C} p_i \log_2(p_i)

For regression trees, CART minimizes Mean Squared Error (MSE), and leaves predict the average target value.

Regularization

Without constraints, decision trees grow until leaves are pure, causing overfitting. We regularize using stopping hyperparameters:

  • max_depth: Limits depth.
  • min_samples_split: Minimum samples required to split a node.
  • min_samples_leaf: Minimum samples a leaf must contain.
Code
skinparam backgroundColor transparent
rectangle "Is Feature X <= 2.5?" as Root
rectangle "Leaf: Class A" as Left
rectangle "Leaf: Class B" as Right
Root --> Left : Yes
Root --> Right : No
Is Feature X <= 2.5?Leaf: Class ALeaf: Class BYesNo

Example: Computing Impurity

The following example demonstrates calculating Gini impurity and Information Gain:

python

Interactive Lab

Compute the Gini Impurity of a mixed parent node and its child nodes after a split. Change the class split distributions to see how purity changes.

Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare

Exercise

Test your understanding of Decision Tree scaling requirements:

Why do Decision Trees not require input feature scaling (e.g., Standardization)?

References & Further Reading