Skip to content
AI 知识地图 0.18 · 2026-07-30
关于与纠错文字目录 / Search
Understanding the principles

Decision Trees and Ensemble Methods: Combining Nonlinear Decisions with Split Rules

From impurity, information gain, and pruning to random forests and gradient boosting, understand the advantages of tree models for tabular data and the risk of leakage.

Core idea Decision trees recursively select feature thresholds to make child nodes purer, forming interpretable piecewise rules; a single tree has high variance, random forests use parallel averaging to reduce variance, and gradient boosting uses sequential residuals to reduce bias.
After reading this you should be able to:Calculate split gain; explain the high variance of trees; distinguish bagging from boosting; avoid leakage and incorrect importance.

1Recursive Partitioning of Feature SpaceIntuition

How does a tree turn a complex boundary into a series of if/else rules?

Decision Treeis a predictive model composed of condition nodes and leaves. The input is a row of features; starting from the root node, each node checks a rule, such as “amount ≤ 500,” and sends the sample to the left or right subtree; upon reaching a leaf, a classification tree outputs a class or class probabilities, while a regression tree outputs a numerical mean.

During training, the algorithm compares different features and thresholds at the current node, chooses the cut that best improves the objective, and then repeats the same process on child nodes until stopping conditions such as depth, sample count, or gain are triggered. Repeated axis-aligned splits divide the space into rectangular leaf regions and combine to form step-like nonlinear boundaries.

A path can explain which rules the model executed this time, but it is not equivalent to a causal reason; correlated features and training perturbations may produce alternative paths. Rotated or smooth boundaries may also require many levels, and trees are not compact for all structures.

2Impurity and GainMath

How do we compare candidate splits?

Impurity IMeasures how mixed the target is in a node: for classification you can use Gini or entropy; for regression you can use target variance. A candidate split divides the parent node into left and right child nodes; it should be weighted by the number of samples on each side, rather than looking only at the purer side.

Gain=I(parent)−(nL/n)I(L)−(nR/n)I(R)

Gain is the impurity decrease;I(parent) is the parent node impurity,I(L) and I(R) are the left and right node impurities;n is the parent node sample count,nL and nR are the left and right sample counts. The larger the gain, the more it indicates that the split makes the weighted child nodes more homogeneous.

For continuous features, valid thresholds are usually scanned between adjacent sorted values; for categorical features, candidate groupings need to be defined. The greedy algorithm only selects the best split for the current node and does not guarantee the entire tree is globally optimal; high-cardinality features may also obtain inflated gain because they have more candidate opportunities.

3Why a Single Tree OverfitsBoundaries

What happens if a tree keeps splitting until every leaf has one sample?

A single tree still takes training samples as input and outputs a set of split rules and leaf predictions. When the tree keeps splitting until leaves have very few samples, it fits not only stable patterns but also exploits chance details such as noise, IDs, and missingness patterns to drive training error very low.

Such a model hashigh variance: slight changes in the training data may alter early thresholds, and the whole subsequent subtree rearranges accordingly. In practice, it is common to see near-perfect training performance and clearly worse validation, many leaf probabilities close to 0 or 1, and unstable structure across resampling.

You can limit maximum depth, minimum leaf samples, and minimum gain, or grow the tree first and then prune, and use independent validation to choose the strength. Overly strong limits cause underfitting; if the problem stems from data leakage, regularization and pruning cannot repair contaminated evidence.

4Random Forest: Parallel Variance ReductionBagging

Why is averaging many high-variance trees more stable?

Random Forestis a bagging method that trains many decision trees in parallel and then aggregates their outputs. The input is the same training set; each tree draws a bootstrap subset from the samples with replacement, and at each split looks only at a random feature subset; at output time it votes for classification and averages for regression.

Averaging can cancel out the random errors of different trees, but the premise is that the trees should not be highly correlated. Bootstrap changes the samples seen, and random features let trees explore alternative splits; together they reduce correlation. If every tree relies on the same strong leakage feature, adding more trees will not solve the problem.

Results should be evaluated by independent validation, out-of-bag estimation, inter-tree correlation, memory, and latency. Random forest is usually more stable than a single tree, but the model is larger and the explanation of an individual prediction is more indirect; time series or entity-grouped data also cannot be bootstrapped arbitrarily.

5Gradient Boosting: Stepwise Residual CorrectionBoosting

What are the later trees learning?

Gradient boostingGradient boosting adds weak trees sequentially. The input consists of the samples, the current ensemble prediction, and the loss function; each round computes the negative gradient of the loss with respect to the current prediction, fits a new tree to these correction targets, then multiplies by the learning rate and adds it to the existing model, producing an updated ensemble prediction.

Under squared loss, the negative gradient is exactly equal to "true value − current prediction", so it is often said that later trees fit residuals; under other losses, the target is the corresponding negative gradient, not necessarily an ordinary numeric residual. A small learning rate with more rounds is usually more stable, and tree depth controls the order of interactions a single round can express.

A continuously decreasing training loss does not mean that unseen performance continues to improve; too many rounds, overly deep trees, or an excessively large learning rate will all chase noise. You should use an entity- and time-isolated validation set for early stopping, and jointly tune sampling, L1/L2, and tree structure.

6Engineering Pitfalls of Tabular DataEngineering

Does not needing standardization for trees mean data preparation is not important?

Trees compare individual features by thresholds and generally do not need standardization for numerical scale; however, inputs must still satisfy availability at prediction time, stable meaning, and split independence. Time leakage, full-data target encoding, after-the-fact fields, duplicate entities, missingness mechanisms, and high-cardinality IDs can all be quickly exploited by trees.

The feature importance produced by training also has different definitions: impurity-decrease importance favors variables with many values and many split opportunities; permutation importance measures the performance change after shuffling a field; SHAP allocates contributions to the current model prediction. All three describe model dependence, not automatically a causal effect.

Acceptance should include feature-availability-time audits, out-of-time validation, entity grouping, target-shuffling tests, and sensitive slicing, and monitor missingness rate and category-set drift. If online missingness routing or new category changes occur, the model still outputs, but the meaning of the path may have already become invalid.

Feature importance does not equal causality. It only indicates the current model's predictive dependence on that variable or its surrogate variables.

7Complete hand calculation: how much does one threshold reduce Gini impurity?Step-by-step calculation

Six sample labels [churn, churn, stay, stay, stay, churn]; is splitting by the amount threshold worthwhile?

Parent node has 3 churn and 3 stay, Gini=1−(3/6)²−(3/6)²=0.5The candidate threshold puts the two records on the left both as “churn,” and the four records on the right contain 1 churn and 3 stay.

GiniL=0; GiniR=1−(1/4)²−(3/4)²=0.375
Gain=0.5−(2/6)×0−(4/6)×0.375=0.25

The tree compares all valid features/thresholds and selects the maximum gain. If a high-cardinality ID can nearly isolate samples one by one, it may get a spurious high gain, so you need to limit leaf samples and prevent leakage.

Nodechurn/stayGini
Parent3/30.500
Left2/00
Right1/30.375

8Original figure: Axis-aligned splits combine into stepwise boundariesVisualization

Each node has only one threshold—how can the entire tree represent nonlinearity?

Multiple axis-aligned splits form rectangular leaf regionsAmount ≤ 500?Leaf: RefundCount ≤ 3?staychurn

Scroll horizontally to view the full diagram on small screens.

Figure 1 A single rule is linear and readable; multi-layer combinations produce staircase-like nonlinearity; rotated boundaries may require many layers.

9Pre-pruning and post-pruning control leaf degrees of freedomPruning

Why is growing fully and then pruning sometimes better than limiting depth at the start?

Pre-pruning uses max_depth, min_samples_leaf, and min_gain to stop early; it is computationally cheap but may miss “weak first, then strong” combined splits. Cost-complexity pruning grows a large tree first, then selects a subtree:

Rα(T)=R(T)+α|leaves(T)|

Increasing α prefers fewer leaves. You must generate the pruning path on the training fold, select α on validation, then evaluate on the test set. Leaf probabilities are estimated from finite sample frequencies, and deep leaves are often extremely overconfident; smoothing and calibration can be added.

SymptomDiagnosisControl
Perfect training score, poor validationLeaves too smallPrune / minimum leaf
Too many probabilities of 0 or 1High leaf frequency varianceSmoothing / calibration
Structure changes dramatically across samplesHigh varianceRandom forest / Bagging

10Missing Values, Categorical Variables, and Time Leakage Determine Real ReliabilityData Boundary

Trees don't require standardization, so why can the data pipeline still ruin the model?

Missingness may itself have business meaning, or it may be caused by collection failures; you can use explicit missing-value branches, surrogate splits, or within-fold imputation. High-cardinality categorical variables will directly leak labels if target encoding uses the full data; temporal data must be split by occurrence time, and future statistics must not enter past samples.

Trees can easily memorize proxies such as user IDs, postal codes, or timestamps. Before launch, perform feature availability point-in-time audits, target shuffling detection, out-of-time validation, and sensitive attribute slicing. When missing rates or category sets drift, even if the model still outputs, the routing path may completely change.

"No standardization needed" is not the same as "no governance needed."Trees are especially good at exploiting leakage fields.

11Common Misconceptions and Learning PathMisconceptions and Dependencies

Readable rules do not automatically equal stability, causality, or fairness.

MisconceptionMore Accurate Understanding
A single tree naturally does not overfitDeep trees can memorize individual samples
Greedy splitting yields the globally optimal treeEach step only optimizes the current node
Feature importance represents causal influenceIt only reflects the current model's prediction dependence
In random forests, the stronger each tree is, the betterDecorrelation is also needed to reduce variance
Boosting is just many trees votingLater trees correct errors according to the current loss gradient
LevelDependencies and Extensions
PrerequisitesProbability, entropy/Gini, bias–variance
This page's coreGreedy splitting, pruning, leaf probability
EnsembleRandom forest, gradient boosting, XGBoost
GovernanceTime leakage, calibration, fairness, drift

12Random forest reduces variance by reducing the correlation between treesBagging mechanism

Why is simply training several identical trees not necessarily effective?

If each tree has variance σ² and the correlation between the errors of two trees is ρ, the variance of the average of B trees is approximately ρσ²+(1−ρ)σ²/B. Increasing B only removes the uncorrelated part; if all trees always use the same strong feature, ρ is high and the benefit saturates quickly.

Var(mean)≈ρσ²+(1−ρ)σ²/B

Bootstrap changes the training samples, and random feature subsets enable different trees to explore alternative splits, thus reducing ρ. Out-of-bag samples can estimate generalization and permutation importance, but time series or grouped data cannot be arbitrarily bootstrapped; otherwise leakage still occurs. Increasing the number of trees usually does not increase bias, but it increases memory and latency.

13Gradient boosting advances in small steps along the negative gradient in function spaceBoosting mechanism

Why is “fitting residuals” only a special case under regression squared loss?

In the formula i is the sample index,m is the boosting round;yᵢ is the true target,xᵢ is the input;Fₘ₋₁ is the previous round’s ensemble prediction function,L is the loss,rᵢₘ is this round’s negative gradient target;hₘ is the new tree,η is the learning rate.

rᵢₘ=−[∂L(yᵢ,F(xᵢ))/∂F(xᵢ)]F=Fₘ₋₁; Fₘ=Fₘ₋₁+ηhₘ

The negative gradient of the squared loss equals y−F, so the new tree fits the residuals; logistic loss instead fits the gradient on the probability scale. A small learning rate η with more rounds is usually more stable, tree depth controls interaction order, and row/column sampling plus L1/L2 limit overfitting.

KnobMain effect when increasedRisk
Tree depthHigher-order interactionsOverfitting, latency
Learning rateLarger correction per roundOvershoots the stable solution
RoundsMore complete fittingChases noise in later rounds
Sampling rateUses more data/featuresIncreases correlation between trees

Early stopping requires a validation set that is temporally and entity-isolated; the test set cannot double as early-stopping monitoring.

14Explaining a Single Path Still Requires Describing Alternative Paths and Related FeaturesInterpretation boundary

Is “rejected because the amount is greater than 500” a complete reason?

The path only describes the model's execution rule for the current input; related features may substitute for one another, and slightly changing the training sample may switch to another threshold. Local SHAP, permutation importance, and path explanation answer different questions, and none are causal conclusions. The explanation should simultaneously provide the prediction version, input values, missing value handling, adjacent threshold sensitivity, and appealable rules, avoiding packaging proxy variables as true causes.

15Connecting the causal chainSynthesis

How does this concept connect from the problem all the way to verifiable practice?

  1. Candidate thresholds partition the samples
  2. Impurity gain selects the split
  3. Recursion forms piecewise rules
  4. A single tree has high variance
  5. bagging averages or boosting corrects errors step by step
  6. Temporal splitting and independent validation determine generalization

16Misconceptions and Self-testSelf-test

Can you explain its mechanism, boundaries, and validation methods without memorizing terminology?

  1. What does split gain measure?
  2. Why is a single tree unstable?
  3. How does random forest decorrelate?
  4. What do the trees learn after Boosting?
  5. Does importance equal causality?
  6. Suppose “Decision Trees and Ensemble Methods: combining nonlinear decisions with split rules” performs normally on offline examples, but after going live the core results decline. How would you localize the problem according to input, internal transformation, output feedback, and applicable boundaries?
  7. How would you design a minimal controlled experiment for “Decision Trees and Ensemble Methods: combining nonlinear decisions with split rules” to prove that the observed improvement comes from the core mechanism, not from simultaneous changes in data, prompts, permissions, or evaluation criteria?
Reference answers
  1. The decrease in impurity of child nodes relative to the parent node.
  2. High variance; sample perturbations can change the structure.
  3. Bootstrap samples and random feature subsets.
  4. The residual or negative gradient of the current loss.
  5. Not equal.
  6. First save the same failing sample and environment, and confirm that the input, permissions, and preconditions have not drifted; then record key intermediate states and check whether the mechanism completes the transformation as described on this page; then compare the raw output against independent metrics and manual final verification; finally retest with boundary examples and controlled experiments. Only after locating the first step that deviates from expectation can you determine whether to modify data, mechanism, evaluation, or usage boundaries.
  7. Fix the data, model version, prompts, permissions, budget, and evaluation; change only one factor directly related to the core mechanism, and repeat across multiple samples and random seeds; at the same time, save intermediate states and failure samples. If the difference appears stably only when the target factor changes, then it supports the mechanism explanation; otherwise continue investigating confounding variables.
Sources and adaptation notes
Accessed: 2026-07-22