Skip to content
GATEiit

GATE DA · Machine Learning

Decision trees

Decision trees split the data with one feature test at a time; you choose splits by information gain (entropy) or Gini impurity, control overfitting by depth limits and pruning, and use variance reduction for regression trees.

Before you start

Concept notes

1. How a decision tree predicts

A decision tree is a flowchart. Each internal node tests one feature (e.g. xj≤t for a numeric feature, or xj=v for a categorical one), each branch is an outcome, and each leaf gives a prediction: the majority class of its training points (classification) or their mean (regression).

To predict, start at the root and follow the branches until a leaf.

Properties:

  • Axis-parallel boundaries: single-feature tests cut the feature space into rectangles (boxes). A diagonal boundary needs many steps.
  • No feature scaling needed, handles mixed numeric and categorical data, and is easy to read as if-then rules.
  • Greedy construction (ID3, C4.5, CART): at each node choose the split that most reduces impurity, then recurse. Greedy choice does not guarantee the globally best tree (finding that is NP-hard).
  • A tree grown until every leaf is pure has zero training error on data without conflicting labels, so it overfits easily.
  • Trees are unstable: small changes in the data can change the top split and the whole tree (high variance). Ensembles such as random forests average many trees to fix this.

For a numeric feature with m distinct sorted values, only the m−1 midpoints between consecutive values need to be tried as thresholds.

Income ≤ 5 lakh?[6+, 6−] yesno Age ≤ 30?[1+, 5−] leaf: +[5+, 1−] yesno leaf: +[1+, 0−] leaf: −[0+, 5−] internal node: test on one feature leaf: majority class of its points
A small classification tree; counts in brackets are [positives, negatives] reaching each node

2. Entropy and information gain

For a node with class proportions p1,…,pK, the entropy is H=−∑k=1Kpklog⁡2pk(with 0log⁡0=0).

  • H=0 for a pure node; H is largest, log⁡2K, when all classes are equally likely. For two classes the maximum is 1 bit, at p=0.5.

A split sends the n points of a parent node S into children S1,…,Sm. The information gain is the drop in entropy, with children weighted by size: IG=H(S)−∑v∣Sv∣∣S∣H(Sv). ID3 chooses the feature with the largest information gain. IG is never negative.

Bias towards many-valued features: a feature like a customer ID splits the data into pure singletons and gets maximal gain, yet it is useless. C4.5 corrects this with the gain ratio: GR=IGSplitInfo,SplitInfo=−∑v∣Sv∣∣S∣log⁡2∣Sv∣∣S∣.

Useful values: H(12,12)=1, H(14,34)≈0.811, H(13,23)≈0.918, H(16,56)≈0.650.

3. Gini impurity and misclassification error

CART uses the Gini impurity G=1−∑kpk2, the probability that two points drawn at random (with replacement) from the node have different classes. G=0 for a pure node and is largest, 1−1K, for a uniform node (0.5 for two classes).

The split is chosen to minimise the weighted child impurity ∑v∣Sv∣∣S∣G(Sv), i.e. to maximise the Gini decrease.

Misclassification error E=1−max⁡kpk is a third measure. It is less sensitive to changes in the class proportions and often fails to separate good splits, so it is mainly used for pruning, not for growing.

Measure Formula Max (2 classes) Used by
Entropy −∑pklog⁡2pk 1 ID3, C4.5
Gini 1−∑pk2 0.5 CART
Misclassification 1−max⁡pk 0.5 pruning

Entropy and Gini usually choose the same split. For two classes with proportion p: entropy H(p), Gini 2p(1−p), error min⁡(p,1−p); all are 0 at p=0 or 1 and peak at p=0.5.

4. Overfitting, pruning and regression trees

A deep tree has low bias and high variance. Ways to control it:

  • Pre-pruning (early stopping): limit the maximum depth, require a minimum number of points to split a node or to form a leaf, or stop when the impurity decrease is below a threshold.
  • Post-pruning: grow a full tree, then remove subtrees that do not improve validation performance. Cost-complexity pruning (CART) minimises Error(T)+α ∣leaves(T)∣, with α chosen by cross-validation.

A tree of depth D with binary splits has at most 2D leaves and 2D−1 internal nodes.

Regression trees predict the mean yˉ of each leaf. A split is chosen to minimise the total sum of squared errors of the children, ∑i∈L(yi−yˉL)2+∑i∈R(yi−yˉR)2, which is the same as maximising the variance reduction. The resulting prediction is a step function of the inputs.

Trees in ensembles:

  • Bagging / random forests: train many deep trees on bootstrap samples (random forests also pick a random subset of features at each split) and average; this cuts variance.
  • Boosting: fit shallow trees one after another to the current errors; this cuts bias.

Formulas to remember

Entropy
H(S)=−∑kpklog⁡2pk
Information gain
IG(S,A)=H(S)−∑v∣Sv∣∣S∣H(Sv)
Gini impurity
G(S)=1−∑kpk2
Gain ratio
GR=IG−∑v∣Sv∣∣S∣log⁡2∣Sv∣∣S∣
Binary entropy
H(p)=−plog⁡2p−(1−p)log⁡2(1−p)
Regression split cost
∑i∈L(yi−yˉL)2+∑i∈R(yi−yˉR)2

Common mistakes

  • Forgetting to weight child entropies by the fraction of points in each child.
  • Using the natural log in entropy when the answer is expected in bits (log⁡2).
  • Choosing the split with the largest child entropy; ID3 maximises gain, i.e. minimises the weighted child entropy.
  • Treating Gini's maximum as 1; for two classes it is 0.5, and 1−1/K in general.
  • Believing a deeper tree is always better because its training error is lower.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Choosing a split by information gain

numerical

A node has 8 points: 4 positive, 4 negative. Split A gives children (3+, 1−) and (1+, 3−). Split B gives (4+, 2−) and (0+, 2−). Which split does ID3 choose?

  1. Step 1: Find the parent entropy.

    Try it on paper first.

Example 2: The same choice with Gini

numerical

Use the same node and splits. Compare the weighted Gini impurity of the children.

  1. Step 1: Gini of the parent.

    Try it on paper first.

Example 3: A regression tree split

numerical

Feature x=1,2,3,4,5,6 with targets y=1,2,3,10,11,12. Compare the SSE before splitting and after the split x≤3.

  1. Step 1: SSE of the root.

    Try it on paper first.

Example 4: Why an ID feature wins and why that is bad

conceptual

A dataset of 100 customers has a unique Customer-ID feature. Why would ID3 choose it at the root, and how does C4.5 avoid this?

  1. Step 1: Compute the gain of splitting on ID.

    Try it on paper first.

Previous year questions

1 official GATE DA question on this topic, newest first.

Practise these 1 PYQs →

Topic test

9 questions: up to 1 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.