Machine Learning β€Ί Trees and Ensembles β€Ί Day 162

Day 162: Decision Trees

Day 162 of 365 β€” Decision Trees

Master the theory, mathematics, and implementation of Decision Trees from first principles: why trees partition feature space into axis-aligned hyper-rectangles, how Gini impurity and Shannon entropy measure node homogeneity, how the CART algorithm searches greedily for optimal split thresholds, why unpruned trees suffer from high variance and overfitting, and how hyperparameter constraints and pruning restore generalization.

Course
Machine Learning
Category
Trees and Ensembles
Reading time
β‰ˆ 50 min
Practical time
β‰ˆ 60 min
Lesson duration
1h 50m
Last verified
2026-08-29

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/machine-learning/day-162-decision-trees

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path β€” section / subsection / week / day:
    cd labs/sections/machine-learning/day-162-decision-trees
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work β€” read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters

In Weeks 21 through 23, we studied linear models: linear regression, logistic regression, and their regularized variants. Linear models possess an undeniable elegance: they compute a weighted sum of inputs w^T x + b, evaluate a scalar threshold, and produce decisions with microsecond latency.

Yet linear models carry a severe structural limitation: they can only separate classes with flat, linear hyperplanes.

If your data contains non-linear interactions (for example, high blood pressure is only dangerous if cholesterol is also elevated), linear models require manual polynomial feature engineering. If your data contains categorical variables with complex hierarchies, linear models require high-dimensional one-hot encodings. If your features have vastly different scales (e.g. income in dollars vs age in years), linear models require standardizing scalers.

Decision Trees break free from these geometric restrictions entirely.

A decision tree is a non-parametric model that recursively partitions feature space into axis-aligned rectangular boxes. Trees automatically discover non-linear relationships and high-order feature interactions, accept numerical and categorical features without scaling, handle missing values seamlessly, and present their learned logic as human-readable if-then-else decision rules.

Furthermore, decision trees serve as the foundational atomic building blocks for the most powerful tabular learning algorithms in history: Random Forests (Day 163) and Gradient Boosted Trees (Days 164–165). Understanding how a single tree splits, grows, and overfits is the prerequisite for mastering all modern tabular machine learning.


The idea in plain language

Imagine playing a game of 20 Questions with a doctor who is diagnosing a patient:

Each question is a simple binary split on a single feature: x_j <= threshold.

As you follow the questions from the root of the tree down to the leaves, each step narrows down the diagnosis. When you reach a terminal leaf node, the tree makes a final prediction: β€œClass = Influenza” or β€œClass = Healthy”.

In geometric terms, each question draws an orthogonal, axis-aligned line across your feature space. Two questions carve the 2D plane into four rectangles; three questions carve 3D space into eight rectangular boxes. Inside each box, the tree predicts the majority class of the training samples that landed there.


Historical background

The conceptual origins of decision trees trace back to the Morgan and Sonquist 1963 Automatic Interaction Detection (AID) program.

In 1984, Leo Breiman, Jerome Friedman, Richard Olshen, and Charles Stone published their monumental book Classification and Regression Trees (CART). The CART framework introduced the modern algorithm used across machine learning: binary recursive splitting using Gini Impurity for classification, variance reduction for regression, and Cost-Complexity Pruning to regularize tree growth.

Concurrently in computer science, J. Ross Quinlan developed ID3 (Iterative Dichotomiser 3, 1986) and its successor C4.5 (1993), which used information theory and Shannon Entropy to evaluate multi-way splits.

In 2000, Breiman and Friedman’s insights culminated in ensemble tree algorithms that continue to dominate tabular Kaggle competitions and commercial predictive modeling pipelines worldwide.


What it is β€” and what it is not

To reason about decision trees with rigorous engineering clarity, let us define what a decision tree is and is not:

What it IS:

What it is NOT:


Why it was created and what problems it solves

Decision trees solve five pervasive challenges in tabular machine learning:

  1. Automatic Discovery of Feature Interactions: If feature A only matters when feature B is true, a tree captures this interaction naturally by placing feature A’s split inside feature B’s subtree.
  2. Zero Feature Preprocessing Overhead: Trees require no scaling, no centering, no outlier clipping, and no monotonic transformations.
  3. Intrinsic Multi-Class Support: Impurity metrics (Gini and Entropy) generalize naturally to K classes without requiring One-vs-Rest or One-vs-One wrappers.
  4. Complete Interpretability and Auditability: Every prediction can be explained by tracing a single deterministic path of if-then rules from root to leaf.
  5. Robust Non-Linear Modeling: Trees model complex non-linear decision boundaries with zero manual kernel expansions.

How it works

Let us formulate the mathematics of decision tree induction, impurity functions, greedy split selection, and regularization.

1. Impurity Metrics: Quantifying Node Homogeneity

Let node m contain N_m training samples belonging to K distinct classes. The empirical class probability distribution at node m is:

p_{mk} = (1 / N_m) * sum_{i in Q_m} I(y_i == k)

Where Q_m is the set of samples in node m, and sum_{k=1}^K p_{mk} = 1.0.

How do we measure whether node m is pure (all samples belong to one class) or mixed (samples are evenly scattered)?

A. Gini Impurity (CART Default)

Gini impurity measures the probability that a randomly chosen element from the set would be incorrectly labeled if it were randomly labeled according to the class distribution in the node:

G(Q_m) = 1 - sum_{k=1}^K p_{mk}^2 = sum_{k=1}^K p_{mk} (1 - p_{mk})

B. Shannon Entropy (Information Theory)

Shannon entropy measures the expected information (in bits) required to describe the class label of a sample in node m:

H(Q_m) = - sum_{k=1}^K p_{mk} * log_2(p_{mk})

Gini and Entropy produce nearly identical split rankings in practice. Gini is computationally faster because it requires simple squarings rather than expensive logarithmic evaluations.


2. Greedy Split Selection in CART

At node m, we wish to find a split theta = (j, t) where j is a feature index (1 <= j <= D) and t is a real-valued scalar threshold (t in R).

The candidate split partitions the N_m samples into left and right child subsets:

Q_{left}(j, t) = { x in Q_m | x_j <= t } Q_{right}(j, t) = { x in Q_m | x_j > t }

Let N_L = |Q_{left}| and N_R = |Q_{right}|, with N_L + N_R = N_m.

The weighted child impurity of split (j, t) is:

G(Q_m, j, t) = (N_L / N_m) * H(Q_{left}) + (N_R / N_m) * H(Q_{right})

The Impurity Reduction (Information Gain) is:

Delta H(m, j, t) = H(Q_m) - G(Q_m, j, t)

The CART algorithm evaluates all features j in {1, ..., D} and all candidate midpoint thresholds t, selecting the optimal split:

(j^*, t^*) = argmin_{j, t} G(Q_m, j, t) = argmax_{j, t} Delta H(m, j, t)


3. Recursive Tree Induction Algorithm

Algorithm: BuildTree(Data X, Labels y, current_depth)
1. Check Termination Base Cases:
   - If current_depth >= max_depth
   - Or len(y) < min_samples_split
   - Or all y belong to the same class (Impurity == 0.0)
   - Then Return LeafNode(class = MajorityClass(y))

2. Find Optimal Split:
   - (j*, t*, min_cost) = FindBestSplit(X, y)
   - If no valid split found (e.g. all features identical):
       Return LeafNode(class = MajorityClass(y))

3. Partition Data:
   - Left_Mask = (X[:, j*] <= t*)
   - Right_Mask = ~Left_Mask

4. Recursive Children:
   - LeftChild = BuildTree(X[Left_Mask], y[Left_Mask], current_depth + 1)
   - RightChild = BuildTree(X[Right_Mask], y[Right_Mask], current_depth + 1)

5. Return InternalNode(feature = j*, threshold = t*, Left = LeftChild, Right = RightChild)

4. Overfitting Mechanisms and Regularization

If left unconstrained, a decision tree will continue splitting until every single training sample occupies its own private leaf node (Gini = 0.0, 100% Training Accuracy).

An unpruned tree memorizes noisy training points, outliers, and spurious correlations, creating tiny, jagged decision regions that fail completely on unseen test data.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               DECISION TREE REGULARIZATION TECHNIQUES                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1. max_depth: Limits tree height (e.g. depth 3 to 6).                  β”‚
β”‚ 2. min_samples_split: Minimum samples required to attempt a split.    β”‚
β”‚ 3. min_samples_leaf: Minimum samples required in any leaf node.        β”‚
β”‚ 4. max_leaf_nodes: Maximum total number of terminal leaves allowed.   β”‚
β”‚ 5. ccp_alpha: Minimal Cost-Complexity Pruning penalty.                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Cost-Complexity Pruning (ccp_alpha): Finds the subtree T that minimizes the penalized cost function:

R_alpha(T) = R(T) + alpha * |T|

Where R(T) is the total misclassification rate of tree T, |T| is the number of terminal leaf nodes, and alpha >= 0 is the complexity parameter governing the trade-off between tree size and fit quality.


An everyday analogy

Think of a decision tree as an expert game of 20 Questions:

  1. The Root Question: The player asks the single question that splits the universe of possibilities in half with maximum certainty (β€œIs it alive?”).
  2. The Branching Logic: Depending on the answer, the next question adapts entirely (β€œIs it an animal?” vs β€œIs it made of metal?”).
  3. The Leaf Conclusion: After 5 or 6 well-chosen questions, the player arrives at a high-confidence answer (β€œIt is a Golden Retriever”).
  4. The Overfitting Danger: If the player is allowed 1,000 questions, they will ask: β€œWas it sitting on the corner of 5th and Main at 3:14 PM yesterday wearing a blue collar?” This question perfectly identifies the specific dog in the training sample, but fails to recognize any other dog in the world.

Examples in practice

Let us visualize the equivalence between binary tree hierarchies and orthogonal 2D feature space partitioning.

Diagram showing a binary decision tree alongside its corresponding 2D feature space partitioned into axis-aligned rectangular regions R1, R2, and R3.

The diagram contrasts hierarchical branching rules with the geometric bounding boxes carved out in feature space.

Below is the comparison between Gini Impurity, Scaled Shannon Entropy, and Misclassification Error:

Animated graph comparing Gini Impurity, Scaled Shannon Entropy, and Misclassification Error across class probability p in the interval zero to one.

Let us examine real Python code fitting a decision tree from scratch and comparing it against scikit-learn:

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

# 1. Load Iris Data
iris = load_iris()
X, y = iris.data, iris.target

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.30, stratify=y, random_state=42
)

# 2. Fit Decision Tree with Depth Constraint
tree_clf = DecisionTreeClassifier(
    criterion="gini",
    max_depth=3,
    min_samples_split=4,
    min_samples_leaf=2,
    random_state=42
)
tree_clf.fit(X_train, y_train)

# 3. Evaluate Predictions
train_acc = accuracy_score(y_train, tree_clf.predict(X_train))
test_acc = accuracy_score(y_test, tree_clf.predict(X_test))

print("=== Decision Tree Performance ===")
print(f"Training Accuracy: {train_acc * 100:.2f}%")
print(f"Test Accuracy:     {test_acc * 100:.2f}%")
print(f"Tree Depth:        {tree_clf.get_depth()}")
print(f"Number of Leaves:  {tree_clf.get_n_leaves()}")
print("\nFeature Importances (MDI):")
for name, imp in zip(iris.feature_names, tree_clf.feature_importances_):
    print(f"β€’ {name:20s}: {imp:.4f}")

Implications: security, privacy, performance, scalability, and cost

DimensionCharacteristicPractical Implication
Inference Latency & CostO(depth) integer comparisons.Evaluating a decision tree involves 3 to 10 numerical comparisons, executing in < 10 microseconds with zero matrix multiplications.
Training ComplexityO(D * N * log N * depth).Finding splits requires sorting feature columns. On massive datasets (N > 10M), training a single tree can become memory-intensive.
Data Privacy & LeakageSingle-sample leaf memorization.In unpruned trees, individual leaf nodes can isolate single private records, allowing attackers to infer sensitive user attributes.
Explainability & ComplianceFull rule extraction.Tree logic can be exported directly into SQL CASE WHEN statements, satisfying strict regulatory transparency requirements.

Alternatives: free, open source, and commercial

Tool / FrameworkArchitectureLicense / CostBest Used For
scikit-learn (DecisionTreeClassifier)Optimized C-accelerated CARTFree, BSD Open SourceBaseline tree modeling, fast prototyping, and visualization with plot_tree.
XGBoost / LightGBM / CatBoostBoosted Tree EnsemblesFree, Apache / MITProduction tabular modeling; combines hundreds of shallow trees for state-of-the-art accuracy.
treeliteTree Model CompilerFree, Apache 2.0Compiling tree models into standalone C code for microsecond edge deployment.
RuleFitRule-Extraction Sparse Linear ModelsFree, Open SourceExtracting linear sparse combinations of tree decision rules for high interpretability.

CharacteristicLinear / Logistic Regressionk-Nearest Neighbors (KNN)Single Decision Tree
Decision BoundaryFlat linear hyperplaneComplex curved Voronoi cellsAxis-aligned rectangular boxes
Feature ScalingStrictly requiredStrictly requiredNot required (Scale invariant)
InterpretabilityHigh (Weights w_j)Low (Black box distances)High (If-then rule paths)
Non-Linear RelationshipsRequires manual interactionsNatural non-linear fittingNatural non-linear fitting
Variance / OverfittingLow varianceSensitive to kVery high variance (Needs pruning)

When to use it β€” and when not to

When to USE a Single Decision Tree:

When NOT to use a Single Decision Tree:


Knowledge check

  1. Axis-Aligned Splits: Trees evaluate x_j <= t, creating orthogonal rectangular boundaries.
  2. Gini vs Entropy: G = 1 - sum(p_k^2) is fast and polynomial; H = - sum(p_k log2 p_k) is information-theoretic.
  3. Scale Invariance: Trees depend solely on rank ordering; feature scaling has zero effect.
  4. Regularization: max_depth, min_samples_split, and ccp_alpha prevent leaf-level memorization.

Hands-on exercise

In this hands-on exercise, you will compute Gini impurity, find the optimal split on a 2D dataset, and construct a recursive binary tree node.

import numpy as np

# Step 1: Implement Gini Impurity
def gini(y):
    if len(y) == 0:
        return 0.0
    _, counts = np.unique(y, return_counts=True)
    return float(1.0 - np.sum((counts / len(y)) ** 2))

print("Gini of pure node [0, 0, 0]:", gini(np.array([0, 0, 0])))
print("Gini of balanced node [0, 1]:", gini(np.array([0, 1])))
print("Gini of 70/30 split:", gini(np.array([0]*7 + [1]*3)))

# Step 2: Optimal Split Search
X = np.array([[1.0, 5.0], [2.0, 6.0], [5.0, 2.0], [6.0, 1.0]])
y = np.array([0, 0, 1, 1])

def find_best_split(X, y):
    N, D = X.shape
    best_feat, best_t, best_cost = -1, 0.0, float("inf")
    for j in range(D):
        vals = np.unique(X[:, j])
        threshs = (vals[:-1] + vals[1:]) / 2.0
        for t in threshs:
            l_mask = X[:, j] <= t
            r_mask = ~l_mask
            cost = (np.sum(l_mask)/N) * gini(y[l_mask]) + (np.sum(r_mask)/N) * gini(y[r_mask])
            if cost < best_cost:
                best_cost, best_feat, best_t = cost, j, t
    return best_feat, best_t, best_cost

feat, thresh, cost = find_best_split(X, y)
print(f"\nOptimal Split: Feature x_{feat} <= {thresh:.2f} (Weighted Gini = {cost:.4f})")

Expected output

Gini of pure node [0, 0, 0]: 0.0
Gini of balanced node [0, 1]: 0.5
Gini of 70/30 split: 0.42

Optimal Split: Feature x_0 <= 3.50 (Weighted Gini = 0.0000)

Validate your work

  1. Verify that gini([0, 1]) == 0.50 and gini([0, 1, 2]) == 2/3.
  2. Confirm that find_best_split returns feat = 0 and threshold = 3.50 with Gini = 0.0.
  3. Verify that fitting DecisionTreeClassifier(max_depth=3) achieves >= 95% accuracy on Iris.

Troubleshooting

Common mistakes

  1. Normalizing Features Before Trees: Unnecessary computation that provides zero accuracy benefit.
  2. Growing Unconstrained Trees: Forgetting max_depth or min_samples_leaf leads to severe test-set overfitting.

Practice assignment

  1. Implement Regression Trees (Variance Reduction): Replace Gini impurity with Mean Squared Error MSE = (1/N) * sum (y_i - y_bar)^2 and build a decision tree regressor from scratch.
  2. Implement Feature Importance Calculation: Traverse a fitted tree and compute Mean Decrease in Impurity (MDI) for each feature by summing the impurity drops N_m * Delta H(m) across all internal nodes.

Extension challenge

Implement Minimal Cost-Complexity Pruning from Scratch:

  1. Implement the weakest-link pruning algorithm that iteratively collapses internal nodes with the smallest effective alpha g(t) = (R(t) - R(T_t)) / (|T_t| - 1).
  2. Generate the cost-complexity pruning path (alpha_1, ..., alpha_k) and use 5-fold cross-validation to select the optimal pruning parameter alpha^*.

Quiz

Q1. What is the geometric nature of the decision boundary produced by a standard single-feature Decision Tree?

  1. A piecewise-constant, axis-aligned orthogonal step boundary separating feature space into hyper-rectangles
  2. A smooth diagonal linear hyperplane
  3. A set of concentric circular Voronoi cells
  4. A high-degree smooth polynomial curve
Show answer

Answer: A. A piecewise-constant, axis-aligned orthogonal step boundary separating feature space into hyper-rectangles

Because each internal tree node splits on a single feature using an inequality x_j <= t, all decision boundaries are strictly orthogonal (perpendicular) to the feature axes.

Q2. What is the Gini Impurity of a binary classification node containing 70 Positive samples and 30 Negative samples?

  1. G = 1 - (0.7^2 + 0.3^2) = 1 - (0.49 + 0.09) = 0.42
  2. G = 0.70
  3. G = 0.50
  4. G = 0.21
Show answer

Answer: A. G = 1 - (0.7^2 + 0.3^2) = 1 - (0.49 + 0.09) = 0.42

Gini impurity is defined as 1 - sum(p_k^2). Here, p_pos = 0.7 and p_neg = 0.3, so G = 1 - (0.49 + 0.09) = 1 - 0.58 = 0.42.

Q3. Why are Decision Trees completely invariant to monotonic feature transformations (e.g. scaling, log-transforms, standardizing)?

  1. Because split evaluation depends solely on the relative rank ordering of feature values; transforming x to log(x) or 100*x preserves the exact same sample ordering and split point
  2. Because trees multiply all inputs by a learned weight matrix
  3. Because the Gini formula normalizes all values to [0, 1]
  4. Because decision trees only accept categorical variables
Show answer

Answer: A. Because split evaluation depends solely on the relative rank ordering of feature values; transforming x to log(x) or 100*x preserves the exact same sample ordering and split point

Tree splits evaluate inequalities like x_j <= t based on sample sorting. Any monotonic transformation preserves rank order, leaving the tree structure and predictions completely unchanged.

Q4. What is the primary fundamental weakness (failure mode) of an unconstrained, deeply grown Decision Tree?

  1. High variance and severe overfitting: an unpruned tree will grow until every leaf contains a single sample, memorizing noise and training artifacts
  2. High bias: the tree cannot fit non-linear patterns
  3. Extreme sensitivity to feature scaling
  4. Inability to handle multiclass classification
Show answer

Answer: A. High variance and severe overfitting: an unpruned tree will grow until every leaf contains a single sample, memorizing noise and training artifacts

Without stopping criteria or pruning, a decision tree will split until every training point is isolated in its own pure leaf, achieving 100% training accuracy but failing to generalize to new data.

Q5. How does the CART algorithm select the best feature j* and threshold t* at an internal node m?

  1. It exhaustively evaluates all features and candidate split thresholds, selecting the pair (j*, t*) that minimizes the weighted sum of child node impurities: (N_L / N_m) * Impurity(L) + (N_R / N_m) * Impurity(R)
  2. It computes the gradient of log-loss with respect to feature weights
  3. It randomly selects a feature and places the threshold at the median
  4. It solves the normal equation (X^T X)^-1 X^T y
Show answer

Answer: A. It exhaustively evaluates all features and candidate split thresholds, selecting the pair (j*, t*) that minimizes the weighted sum of child node impurities: (N_L / N_m) * Impurity(L) + (N_R / N_m) * Impurity(R)

CART is a greedy recursive partitioning algorithm that evaluates all possible midpoint thresholds across all features to minimize the weighted child impurity at each step.

Q6. What is the maximum possible value of Gini Impurity for a K-class classification problem?

  1. G_max = 1 - (1/K)
  2. G_max = 1.0
  3. G_max = K
  4. G_max = log2(K)
Show answer

Answer: A. G_max = 1 - (1/K)

When all K classes are equally likely (p_k = 1/K for all k), Gini impurity reaches its maximum: G_max = 1 - sum_{k=1}^K (1/K)^2 = 1 - K * (1/K^2) = 1 - (1/K).

Q7. What is the difference between Pre-Pruning (early stopping) and Post-Pruning (cost-complexity pruning)?

  1. Pre-pruning halts tree growth during training using hyperparameter limits (max_depth, min_samples_leaf); post-pruning grows a full tree first and then collapses subtrees that contribute less impurity reduction than penalty alpha
  2. Pre-pruning applies to classification; post-pruning applies to regression
  3. Pre-pruning uses Gini; post-pruning uses Entropy
  4. There is no mathematical difference
Show answer

Answer: A. Pre-pruning halts tree growth during training using hyperparameter limits (max_depth, min_samples_leaf); post-pruning grows a full tree first and then collapses subtrees that contribute less impurity reduction than penalty alpha

Pre-pruning stops splitting early (which can suffer from premature stopping when complex interactions require multiple splits). Post-pruning builds the full tree and prunes back weak branches using cost-complexity optimization.

Q8. Why is it difficult for a standard Decision Tree to model a simple diagonal linear boundary like x_1 + x_2 = 1?

  1. Because the tree can only make axis-aligned vertical and horizontal splits, forcing it to approximate the smooth diagonal line with a jagged staircase of many rectangular splits
  2. Because decision trees cannot compute addition
  3. Because linear boundaries require negative thresholds
  4. Because diagonal lines have zero Gini impurity
Show answer

Answer: A. Because the tree can only make axis-aligned vertical and horizontal splits, forcing it to approximate the smooth diagonal line with a jagged staircase of many rectangular splits

Axis-aligned splits must approximate continuous diagonal lines using a high-variance staircase approximation, requiring dozens of deep nodes where a single logistic regression hyperplane would suffice.

Glossary

Decision Tree
A non-parametric hierarchical supervised learning model that recursively partitions feature space into axis-aligned rectangular regions based on feature threshold tests.
Gini Impurity
A measure of node label heterogeneity in classification trees: G = 1 - sum(p_k^2), equal to 0.0 for pure nodes and maximized for uniform distributions.
Shannon Entropy
An information-theoretic measure of uncertainty: H = - sum(p_k * log2(p_k)), measuring the expected bits required to encode class labels.
Information Gain
The reduction in entropy achieved by partitioning a node into child subsets: IG = H(Parent) - sum((N_child / N_parent) * H(Child)).
CART (Classification and Regression Trees)
The standard greedy binary recursive partitioning algorithm developed by Breiman et al. using Gini impurity for classification and variance reduction for regression.
Leaf Node
A terminal node in a decision tree that contains no child branches and assigns a final class prediction (or continuous average) to all arriving samples.
Axis-Aligned Split
A decision rule evaluating a single feature against a scalar threshold (x_j <= t), creating boundaries strictly orthogonal to coordinate axes.
Pre-Pruning (Early Stopping)
Regularizing a decision tree by halting recursive growth when predefined stopping thresholds (max_depth, min_samples_split) are met.
Cost-Complexity Pruning
A post-pruning technique that minimizes a cost function balancing tree misclassification error against tree size parameterized by alpha.
Scale Invariance
The property of decision trees where monotonic feature transformations (e.g. scaling or log-transforms) have zero effect on split choices or model predictions.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.