βˆ‘GateAndNet
PlannerSign Up
INTERMEDIATEFrequently Tested 4 min read 5 views

Decision Trees (Entropy vs Gini), Random Forests & Gradient Boosting (XGBoost)

Shannon Entropy, Information Gain, Gain Ratio (C4.5), CART Gini Impurity, Bagging out-of-bag variance formula, AdaBoost sample reweighting, and XGBoost second-order Newton boosting.

1. Impurity Criteria: ID3 vs C4.5 vs CART

Tree AlgorithmSplitting MetricMultiway vs BinaryHandles High-Cardinality IDs?
ID3Information Gain IG⁑(S,A)\operatorname{IG}(S, A)Multiway❌ Biased toward attributes like Roll_No
C4.5Gain Ratio =IG⁑(S,A)SplitInfo⁑(S,A)= \frac{\operatorname{IG}(S, A)}{\operatorname{SplitInfo}(S, A)}Multiway / Binaryβœ… Penalizes large intrinsic split entropy
CARTGini Impurity 1βˆ’βˆ‘pc21 - \sum p_c^2 (or MSE for Regression)Strictly BinaryUses Cost-Complexity Pruning $R_\alpha(T) = R(T) + \alpha
Quick Tip

Rapid Binary Node Calculation (p+=0.5,pβˆ’=0.5p_+ = 0.5, p_- = 0.5):

  • Entropy H=βˆ’0.5log⁑2(0.5)βˆ’0.5log⁑2(0.5)=1.0H = -0.5\log_2(0.5) - 0.5\log_2(0.5) = \mathbf{1.0} bit (maximum for 2 classes; log⁑2K\log_2 K for KK classes).
  • Gini Impurity =1βˆ’(0.52+0.52)=0.50= 1 - (0.5^2 + 0.5^2) = \mathbf{0.50} (maximum for 2 classes; 1βˆ’1/K1 - 1/K for KK classes).

2. Bagging & Random Forests vs Boosting (AdaBoost & Gradient Boosting)

Bootstrap Aggregating (Bagging): Draws BB bootstrap samples of size nn with replacement. Probability a specific instance is never selected in nn draws (Out-of-Bag / OOB):

P(OOB)=(1βˆ’1n)nβ†’nβ†’βˆž1eβ‰ˆ0.3679β€…β€Š(36.8%)P(\text{OOB}) = \left(1 - \frac{1}{n}\right)^n \xrightarrow{n \to \infty} \frac{1}{e} \approx 0.3679 \; (36.8\%)

Thus each bootstrap sample contains β‰ˆ63.2%\approx \mathbf{63.2\%} unique training rows!

  • Random Forest: Combines Bagging + Random Feature Subspace (mβ‰ˆdm \approx \sqrt{d} for classification, d/3d/3 for regression at every split) to decorrelate trees (lowering ρ\rho in ρσ2+1βˆ’ΟBΟƒ2\rho\sigma^2 + \frac{1-\rho}{B}\sigma^2).
  • Gradient Boosting: Fits tree hm(x)h_m(x) sequentially to the negative gradient (pseudo-residuals) rim=βˆ’[βˆ‚L(yi,F(xi))βˆ‚F(xi)]F=Fmβˆ’1r_{im} = -\left[\frac{\partial L(y_i, F(x_i))}{\partial F(x_i)}\right]_{F=F_{m-1}}. XGBoost uses second-order Taylor expansion with gradient gig_i and Hessian hih_i: optimal leaf weight wjβˆ—=βˆ’βˆ‘i∈Ijgiβˆ‘i∈Ijhi+Ξ»w_j^* = -\frac{\sum_{i \in I_j} g_i}{\sum_{i \in I_j} h_i + \lambda}.
Common Exam Mistake

Bagging vs Boosting Exam Classic: Deep unpruned trees have low bias, high variance β€…β€ŠβŸΉβ€…β€Š\implies Bagging / Random Forest reduces Variance (cannot overfit solely by increasing BB). Shallow decision stumps have high bias, low variance β€…β€ŠβŸΉβ€…β€Š\implies Boosting sequentially reduces Bias (can overfit noisy labels if MM is too large!).

Key Formulas Summary
Shannon Entropy & Information Gain (ID3)
H(S)=βˆ’βˆ‘c=1Kpclog⁑2pc,IG⁑(S,A)=H(S)βˆ’βˆ‘v∈Values(A)∣Sv∣∣S∣H(Sv)H(S) = -\sum_{c=1}^{K} p_c \log_2 p_c, \qquad \operatorname{IG}(S, A) = H(S) - \sum_{v \in \text{Values}(A)} \frac{|S_v|}{|S|} H(S_v)
Note: For binary class p in [0,1]: H_max = 1 bit at p = 0.5; H = 0 when node is pure (p=0 or p=1)
Gini Impurity (CART) & Correlated Ensemble Variance
Gini⁑(S)=1βˆ’βˆ‘c=1Kpc2,Var⁑(fΛ‰B)=ρσ2+1βˆ’ΟBΟƒ2\operatorname{Gini}(S) = 1 - \sum_{c=1}^{K} p_c^2, \qquad \operatorname{Var}(\bar{f}_B) = \rho \sigma^2 + \frac{1 - \rho}{B}\sigma^2
Note: Random Forest subsamples m = sqrt(d) features per split to reduce tree correlation rho!
AdaBoost Classifier Weight
Ξ±t=12ln⁑ ⁣(1βˆ’Ο΅tΟ΅t)\alpha_t = \frac{1}{2}\ln\!\left(\frac{1 - \epsilon_t}{\epsilon_t}\right)
Note: If weighted error epsilon_t = 0.5 (random guessing), alpha_t = 0; misclassified weights multiply by e^(+alpha_t)
#Machine Learning#Decision Trees#Entropy#Gini#Random Forest#AdaBoost#XGBoost

Practice Questions on This Chapter (2)

Q1GATE DA MLMCQMEDIUM
+2M β€’ -0.67

A Decision Tree node SS contains 1616 positive and 1616 negative examples. Splitting on binary attribute AA produces left child SLS_L (12+,4βˆ’12+, 4-) and right child SRS_R (4+,12βˆ’4+, 12-). What is the Gini Impurity reduction (Ξ”Gini\Delta \text{Gini}) achieved by attribute AA?

⚑ Click an option above to verify instantly
Q2GATE DA MLMCQMEDIUM
+2M β€’ -0.67

In an AdaBoost iteration, a weak classifier hth_t achieves weighted classification error Ο΅t=1e2+1β‰ˆ0.1192\epsilon_t = \frac{1}{e^2 + 1} \approx 0.1192. What classifier weight Ξ±t=12ln⁑ ⁣(1βˆ’Ο΅tΟ΅t)\alpha_t = \frac{1}{2}\ln\!\left(\frac{1-\epsilon_t}{\epsilon_t}\right) is assigned to hth_t?

⚑ Click an option above to verify instantly
Previous TopicSupport Vector Machines (SVM): Margin Duality, KKT Conditions & Kernel TrickNext Topic PCA Eigen-Directions, K-Means/DBSCAN Clustering & Neural Net Backpropagation