Skip to content
E
Educatum

Why does decision tree have high variance?

Curated by Educatum AI teamLast updated:
Basic Concepts
Direct Answer

Decision trees have high variance because small perturbations in the training data can trigger different greedy splits near the root, cascading into radically different tree structures and predictions. Unconstrained trees partition feature space down to tiny, near-pure leaf subsets that memorize noise and local outliers. Variance is typically controlled by limiting tree depth and leaf size, pruning branches, or averaging many decorrelated trees via bagging and Random Forests.

Study Card: Why Decision Trees Have High Variance

Direct Answer

Unregularized decision trees are classic low-bias, high-variance estimators: small changes to the training sample can yield dramatically different tree structures and test predictions.

Three structural mechanisms drive this high variance:

  1. Greedy, hierarchical splitting: Trees select the single locally best split (e.g., maximizing Gini or entropy gain) at each node. Because every subsequent split only operates inside the partitions created by its ancestors, even a tiny data shift that flips one early split cascades down the entire subtree below it.
  2. Exponentially shrinking sample counts in leaves: After dd splits, a typical leaf contains roughly O(N/2d)O(N / 2^d) observations. Deep leaves make decisions from just a handful of points, causing boundaries to track local label noise.
  3. Axis-aligned step-function flexibility: With no global smoothness penalty or parameter sharing across regions, an unconstrained tree can isolate individual noisy points into hyper-rectangular pockets (low training error, high test variance).

Key Terms

  • Variance: Sensitivity of learned model structure and predictions to random fluctuations across training datasets.
  • Greedy Recursive Partitioning: Top-down algorithm optimizing local impurity reduction at each split without backtracking.
  • Cascading Split Sensitivity: Instability where changing an upper-level split alters every downstream partition.
  • Pruning & Depth Constraints: Limiting max_depth, increasing min_samples_leaf, or applying cost-complexity pruning (ccp_alpha) to curb overfitting.

Example

Suppose we fit an unrestricted decision tree on a noisy two-moons classification dataset, then perturb the training inputs slightly (or draw a different bootstrap subsample). Even minor noise near a boundary flips the optimal root split threshold or feature, rearranging the lower branches and flipping predictions on numerous test points. Averaging predictions across many bootstrapped trees (Bagging / Random Forest) smooths out these discrete boundary jumps.

Code Implementation

import numpy as np
from sklearn.datasets import make_moons
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier

# Generate noisy non-linear classification dataset
X, y = make_moons(n_samples=200, noise=0.25, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)

# Unconstrained tree overfits training noise
tree = DecisionTreeClassifier(random_state=42)
tree.fit(X_train, y_train)
print(f"Original tree -> Train acc: {accuracy_score(y_train, tree.predict(X_train)):.3f}, "
      f"Test acc: {accuracy_score(y_test, tree.predict(X_test)):.3f}, "
      f"Nodes: {tree.tree_.node_count}, Root: feature {tree.tree_.feature[0]} <= {tree.tree_.threshold[0]:.3f}")

# Small perturbation in training data changes structure and test predictions
rng = np.random.default_rng(42)
X_train_perturbed = X_train + rng.normal(0.0, 0.08, size=X_train.shape)
tree_perturbed = DecisionTreeClassifier(random_state=42)
tree_perturbed.fit(X_train_perturbed, y_train)

pred_disagreement = np.mean(tree.predict(X_test) != tree_perturbed.predict(X_test))
print(f"Perturbed tree -> Test acc: {accuracy_score(y_test, tree_perturbed.predict(X_test)):.3f}, "
      f"Nodes: {tree_perturbed.tree_.node_count}, Root: feature {tree_perturbed.tree_.feature[0]} <= {tree_perturbed.tree_.threshold[0]:.3f}")
print(f"Test prediction disagreement after tiny input noise: {pred_disagreement:.1%}")
  • Bias–Variance Tradeoff: Unrestricted trees have very low bias and very high variance; pruning increases bias slightly while sharply reducing variance.
  • Bagging & Random Forests: Train multiple deep trees on bootstrap samples (and random feature subsets) and average them, directly suppressing variance without increasing bias significantly.
  • Boosting (Gradient Boosting / XGBoost): Primarily reduces bias by sequentially combining shallow weak-learner trees (max_depth 3–83\text{--}8), while controlling variance via small learning rates (shrinkage), subsampling, and leaf regularization.
  • Cost-Complexity Pruning (ccp_alpha): Prunes subtrees whose impurity improvement fails to exceed a complexity penalty α\alpha per added leaf.
View all →

Try keywords like RoPE, FlashAttention, DPO, or Blind 75.