MACHINE LEARNING / 3. DECISION TREES
Decision Trees
Interpretable splits — the building block of ensemble methods
EXPLANATION
A decision tree recursively splits the feature space into regions, making predictions based on the majority class (classification) or mean value (regression) in each region. At each node, it finds the split that best separates the data. Metrics for finding best split: • Gini Impurity → measures class mixing. Gini = 1 - Σpᵢ² (used in CART) • Information Gain / Entropy → entropy = -Σpᵢ·log(pᵢ) (used in ID3, C4.5) • MSE reduction → for regression trees Key hyperparameters: • max_depth → how deep the tree grows. Deeper = more overfit • min_samples_split → min samples needed to split a node • min_samples_leaf → min samples in a leaf node Decision trees are highly interpretable but overfit badly on their own. Their real power comes from ensembles — Random Forest and Gradient Boosting both use trees as base learners.
DATA FLOW
Feature space splitting:
Is age > 30?
├── YES: Is income > 50k?
│ ├── YES: → Predict "Buy" (leaf)
│ └── NO: → Predict "No Buy" (leaf)
└── NO: Is student?
├── YES: → Predict "Buy" (leaf)
└── NO: → Predict "No Buy" (leaf)
Gini at a node: 1 - (p_class1² + p_class2²)
Pure node (all same class): Gini = 0
Max impurity (50/50 split): Gini = 0.5CODE