DS701 Session 9 — Mon Oct 5, 2026
A tree is fit to a table of loans. What is the learned object, and how is a new loan classified?
We split on Home Owner, then Marital Status, then Income, and error dropped to 0%. Why do we bother with Gini or entropy instead of just minimizing error?
The full Titanic tree drove training error to ~0 but did worse on the validation set than the one-rule model predict survived = (Sex == female). What happened?
The search is greedy and local — the best split now is never revisited, so the tree is not the globally optimal tree. Finding that one is NP-hard.
{Small, Medium} | {Large, X-Large} is legal, {Small, Large} | {Medium, X-Large} is not.
Pick the threshold with the lowest weighted impurity.
\[ \begin{aligned} \textnormal{Gini} &= 1 - \sum_{i=0}^{c-1} p_i(t)^2 \\ \textnormal{Entropy} &= -\sum_{i=0}^{c-1} p_i(t) \log_2 p_i(t) \\ \textnormal{Error} &= 1 - \max_i p_i(t) \end{aligned} \]
\(p_i(t)\) = relative frequency of class \(i\) at node \(t\); \(0 \log_2 0 = 0\).
Score a split by the weighted average over its children and take the largest gain:
\[ I(\textnormal{ch}) = \sum_{j=1}^{k} \frac{N(v_j)}{N} I(v_j), \quad \Delta = I(\textnormal{parent}) - I(\textnormal{ch}) \]

scikit-learn’s default.
max_depth, min_samples_split / min_samples_leaf, minimum impurity decrease.ccp_alpha).min_samples_split=20 and max_depth=3 beat the unrestricted tree on validation error — less tree, better model.Catch: bagged trees are correlated. If one feature dominates, every tree splits on it first and the trees look nearly identical — so averaging buys much less than it should.
max_features, commonly \(m \approx \sqrt{p}\)).max_features from 1 to all 30 and measure the trees decorrelating (their pairwise prediction correlation drops) while the OOB score barely moves.On Titanic, a 100-tree RandomForestClassifier beat every single tree we fit. A forest is a strong, low-effort baseline for tabular data — no feature scaling, mixed types welcome, automatic feature selection. Try one before anything fancier.
Trees hand you an importance score for free. Four ways it will mislead you:
Goal: compute impurity by hand, watch a tree overfit as depth grows, fit a random forest and sweep max_features, then deliberately break the feature importances — noise, duplicates, cardinality — and compare against permutation importance.
The activity notebook goes live on the day of the lecture. Colab is optional — you can also open it on GitHub and run it locally.
Full lecture notes: Decision Trees and Random Forests
Reference: Tan, Steinbach, Karpatne & Kumar, Introduction to Data Mining, Ch. 3–4.