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?
Answer: the learned object is a set of axis-aligned (e.g. single feature) test conditions (one per internal node) plus a class label at each leaf. A new record is routed down the tree by evaluating one attribute test at a time until it lands in a leaf; the leaf’s majority class is the prediction. No distances, no weights, no gradient — just a nested partition of feature space into boxes.
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?
Answer: classification error counts only the points in each node’s minority class. If a split leaves the same class in the majority in every child, that count doesn’t change, so the error gain is zero, even when the split makes the children much purer.
Home Owner splits the loans (7 No, 3 Yes) into 3 No / 0 Yes and 4 No / 3 Yes:
The greedy search needs that signal: if error scores many candidate splits as 0 (or as ties), it can’t tell a useful split from a useless one. Gini and entropy are strictly concave, so any split whose children have different class proportions from the parent gets a positive gain.
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?
Answer: overfitting — the fully grown tree kept splitting until leaves held one or two passengers, so it memorized noise in the training split. It is a low-bias, high-variance model. The one-rule model has high bias but almost no variance, and on this data the variance term dominates the error.
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: advise a consortium of Boston hospitals on whether nucleus measurements from breast biopsies can flag likely-malignant samples — find the best single cutoff, choose a tree depth that generalizes, and decide whether a random forest is worth giving up a readable tree.
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.