Data Mining & Visualization

Online B.Com · Sem 5

Lesson 1 of 5Analytics

Decision Trees for Classification

Data Mining & Visualization

About the video

Decision and Classification Trees, Clearly Explained!!!

StatQuest with Josh Starmer

Study notes

A decision tree classifies records by repeatedly splitting the data on attribute tests until the leaves are mostly one class. Splits are chosen to maximise purity, measured by Gini impurity or entropy and information gain. Pruning and depth limits stop overfitting.

Structure

  • Root node: the first split on the whole dataset.
  • Internal nodes: tests on an attribute (e.g. Age < 30?).
  • Branches: the outcomes of a test.
  • Leaf nodes: the predicted class, usually the majority class of the training records in that leaf.
  • A new record is classified by following the tests from the root down to a leaf.

Choosing splits

  • Greedy top-down recursive partitioning: at each node, pick the split that best separates the classes.
  • Entropy = -sum p_i log2(p_i). It is 0 for a pure node and 1 for a 50/50 two-class node.
  • Information gain = entropy(parent) - weighted average entropy(children).
  • Gini impurity = 1 - sum p_i^2. Its maximum is 0.5 for two balanced classes.
  • Splitting stops when nodes are pure, too small, or the maximum depth is reached.

Overfitting and pruning

  • Deep trees memorise noise: high training accuracy but poor test accuracy.
  • Pre-pruning limits depth, minimum samples per leaf, or minimum gain.
  • Post-pruning grows the full tree, then cuts branches that do not improve validation performance.
  • Pros: interpretable, handles mixed data types, needs no feature scaling.
  • Cons: unstable (small data changes alter the tree) and prone to overfitting.

Key terms

Leaf node
A terminal node that assigns a class prediction.
Entropy
A measure of class impurity in a node: -sum p log2 p.
Information gain
The reduction in entropy achieved by a split.
Gini impurity
1 - sum p_i^2; the probability of misclassifying a randomly labelled record.
Pruning
Removing branches to reduce overfitting.

Takeaways

  • Trees split greedily to maximise purity gain.
  • A pure node has entropy 0 and Gini 0.
  • Control depth or prune to avoid overfitting.
  • Trees are highly interpretable rules.
Contribute

Was this lesson helpful?

We read every rating and fix the weakest lessons first.