Statistical Learning II
The second half turns from smooth restrictions (linear models, splines — [[06a_Statistical_Learning_I]]) to algorithmic ones: partition the space (trees), average many unstable fits (bagging, forests), fit residuals greedily (boosting), compose functions of functions (neural nets), maximize a margin (SVMs), or impose no labels at all (unsupervised). The organizing frame from 06a still holds — every method is structure + score + search, and bias–variance is the master dial — but here the search carries the intellectual weight: these criteria are non-convex or combinatorial, so we approximate with greedy recursion, gradient descent, and convex relaxations, and we pay for it in variance. Two recurring cures: average to kill variance (bagging, forests) and bet on sparsity (boosting, the lasso’s spirit). Prerequisites cashed in: bias–variance and shrinkage (06a §2–3), the lasso/L1 idea (06a §3), kernels-as-inner-products and the SVD (track 2), EPE and the conditional mean (06a §1). Closes with missing data and a meta-frame for choosing methods at all.
1. Trees (CART)
- Structure: partition the input space into disjoint rectangles covering it, predict a constant per region: Given the regions, the constants are trivial (the region mean, for squared error); the hard part is the regions. Optimizing over all partitions is NP-hard, so restrict to axis-aligned rectangles built by greedy recursive binary splitting.
- The split criterion (regression): a split is a variable and cutpoint , cutting the current region into the two half-spaces and . Pick the minimizing the post-split RSS, each child predicted by its own mean: Recurse on the children. Categorical predictors: order the levels by their mean , then treat as ordinal (avoids the search).
- Why this dodges the curse: it considers one axis at a time, never searching for neighbors in all dimensions at once — unlike KNN (06a §2).
- Classification — and why misclassification error fails as the split score. Misclassification rate is not a continuous/sensitive function of the split: two children can both have the same majority class (so zero improvement in error) even when the split sharply purifies them. Greedy search needs a differentiable surrogate that rewards purity. Reframe: estimate class probabilities and score the node by squared error on the class indicators . Take one class and split the sum by indicator value: each of the points with contributes , each of the points with contributes :
Substitute and :
Factor out :
Sum over classes — the per-node squared-error risk is times the Gini index
maximal () at uniform, zero at a pure node. Entropy is an equivalent purity measure. Use Gini/entropy to grow (they reward confidence gains); use misclassification error to prune when accuracy is the goal. Numbers (2 classes): a node at has misclassification and Gini ; a split into and children (equal sizes) leaves misclassification but Gini — both improve, yet had the children stayed majority-same-class, misclassification wouldn’t have moved while Gini still would. That gap is why Gini grows trees.
- Right-sized trees — cost-complexity pruning. A single stopping threshold is short-sighted (a weak split can enable a strong one beneath it — e.g. a symmetric interaction). Instead grow a large tree , then prune. Charge per leaf and minimize penalized RSS over subtrees: the Lagrangian form of “best subtree with a budget of leaves.” At the full tree wins; as rises, collapsing a leaf pair pays off exactly when the per-leaf RSS reduction it gave up falls below . Always collapsing the current weakest link (smallest reduction-per-leaf) makes the minimizers a nested sequence , so one bottom-up pass yields the whole path; choose by CV.
- Missing values — surrogate splits: when the primary split variable is missing for an observation, send it down using the most-correlated alternative variable’s split (computed locally within the node). A graceful local imputation, also handles missingness at training time.
Implications
- Trees are interpretable (read the path to any prediction), invariant to monotone transforms of (only order matters ⟹ immune to predictor outliers and scaling), handle mixed/missing data, and do automatic variable selection (a variable matters iff it’s split on).
- But: piecewise-constant ⟹ high bias on smooth/linear truths; data fragmentation ⟹ can’t model dependence on many variables; and high variance — small data changes reshape the tree (the greedy multiplicative structure compounds errors). These three weaknesses are exactly what §2–3 fix.
- The Gini-over-misclassification choice is a general lesson: pick a differentiable surrogate aligned with the goal when the true loss is non-smooth (recurs in SVMs §5, boosting §3).
Core competency set
- Write the regression split objective and the constant-per-region predictor; explain the categorical-ordering trick.
- Explain why misclassification error fails as a split score and derive Gini as squared-error-on-probabilities.
- State cost-complexity pruning and surrogate splits; list trees’ three weaknesses.
2. Bagging and random forests
- Bagging (bootstrap aggregating): trees are high-variance; averaging kills variance. Recall — so fit trees on bootstrap resamples and average: Grow the trees deep and unpruned. The reason: averaging leaves bias untouched and only attacks variance. By linearity the bag has the same expectation as a single tree,
so is fixed no matter how you build the trees — the only term averaging can shrink is the variance. So push each tree to low bias (deep, unpruned) and accept its high variance, which averaging then removes. is not a tuning parameter (more never overfits; pick where the error settles). Cost: lost interpretability (recover variable importance by total RSS/Gini reduction attributed to each variable, averaged over trees).
- Out-of-bag error: each bootstrap sample omits ~1/3 of points; predict each point from the trees that didn’t see it ⟹ a free test-error estimate, no separate CV.
- Random forests — bagging with a twist that fixes bagging’s limit. If one predictor is dominant, every bagged tree splits on it first ⟹ the trees are correlated, and correlation sets a floor on what averaging can do. For identically-distributed trees with variance and pairwise correlation ,
As the second term vanishes but the first, , does not — that is the floor. Driving up can’t beat it; the only lever left is lowering . Fix: at each split consider only a random subset of predictors. This decorrelates the trees — on average of splits ignore the dominant variable, letting others contribute — so averaging bites harder.
- Gain in variance reduction outweighs the small bias from splitting on weaker variables. recovers bagging; small helps most with many correlated predictors. Forests work better for classification than regression (classification is nearly piecewise-constant anyway). Numbers: predictors ⟹ candidates per split, so a dominant predictor is off the menu at of splits — that’s the decorrelation. Picture to hold: bagged trees are a forest of near-copies all forking on the same first variable; the random-subset rule forces them to branch differently, so their errors cancel on averaging.
Implications
- Bagging is the canonical variance-reduction move and applies to any unstable learner, not just trees (dropout in neural nets is its spiritual cousin — averaging over perturbed models).
- The decorrelation insight — averaging helps only to the extent the things averaged are independent — is why RF beats bagging and is a general principle for ensembles.
- OOB makes forests nearly tuning-free off the shelf, a big part of their popularity.
Core competency set
- Explain bagging via and why trees are grown deep/unpruned; define OOB.
- Explain the correlation problem and how decorrelates; state the limit.
3. Boosting and gradient boosting (MART)
The crown jewel: instead of averaging independent trees (bagging), grow them sequentially, each correcting the last. Boosting any weak learner — especially shallow trees — yields top-tier accuracy.
- The model is an additive expansion over a base class (trees). Treating each candidate tree as a feature , this is a (huge, regularized) linear regression in the tree weights. The parameter space is astronomically large ⟹ regularize, and do it by a path, not a full solve.
- The generalized residual (pseudo-response) — the central object. To reduce a general loss by gradient descent in function space, the steepest-descent direction at the current fit is the negative functional gradient Squared-error loss ⟹ (the ordinary residual). Absolute loss ⟹ . So “fit the residual” generalizes to “fit the negative gradient of whatever loss you chose.”
- Gradient boosting (MART) — the algorithm. Initialize const. Repeat:
- Compute generalized residuals at the current .
- Fit a tree to the by least squares — this yields the regions (we keep the partition, discard its leaf values).
- Re-optimize the leaf values for the actual loss. Step 2 fit the tree to the pseudo-residuals by least squares, so its regions track the gradient but its leaf constants are calibrated to that squared-error surrogate, not to — for any non-squared loss the two disagree. So keep the regions, discard their values, and re-solve each region’s constant against the true loss: — disjoint regions make this a separate 1-D optimization each (squared loss ⟹ region mean of residuals, recovering plain residual-fitting; absolute loss ⟹ region median).
- Update with a small learning rate (shrinkage). Stop by monitoring held-out error (it does overfit eventually — visible if you watch probabilities, not just misclassification).
- Why small trees. A depth- tree is a -way interaction (each split multiplies indicators). The functional ANOVA decomposition shows most real functions are dominated by low-order interactions. So a stump (depth 1) = additive/main-effects model; depth 2 = pairwise interactions; rarely more. Tree depth directly controls interaction order — another bias–variance knob.
- Shrinkage + many trees. Small (e.g. 0.01) means many similar trees and a smoother fit; trades against . The optimal-leaf step makes the procedure scale-invariant. Picture to hold: each tree is a small chisel-stroke at the part of the signal the current model still gets wrong; with a tiny learning rate, thousands of gentle strokes accrete into a smooth surface — the opposite of one deep tree’s coarse cuts.
- Classification: model functions with softmax ; under the multinomial deviance the generalized residual is the simple residual on the probability scale ( the class indicator). Boost trees per round (K-MART).
- Robust losses: absolute loss (median updates) is fully robust to -outliers; Huber (quadratic near zero, linear in the tails) gets the efficiency of squared loss with the robustness of absolute — the practical default for messy regression.
Interpreting the black box.
- Variable importance: sum the split-improvements attributed to each variable, averaged over all trees — . More stable than a single tree’s.
- Partial dependence: to see how depends on a subset marginalizing the rest, average over the data: then plot. It is the best additive approximation in — not the same as conditioning on (which would confound through correlated variables; the hospital-success-rate paradox).
Implications
- Boosting operates on the output of a weak learner, not its internals — a generic accuracy amplifier (it boosts any base learner, trees just respond especially well).
- The generalized-residual view unifies regression, classification, and robust losses under one algorithm: change , the only thing that changes is the residual you fit.
- Boosting (sequential, bias-reducing) and bagging/RF (parallel, variance-reducing) are complementary — XGBoost adds explicit regularization on top of the boosting path and dominates tabular competitions.
Core competency set
- Derive the generalized residual and give it for squared and absolute loss.
- State the MART loop (residual → tree for regions → re-optimize leaves → shrunken update) and why it re-optimizes leaves.
- Explain tree depth = interaction order via the ANOVA decomposition; define partial dependence and why it ≠ conditioning.
4. Neural networks
- Structure: a linear combination of nonlinear functions of linear combinations — one hidden layer: an activation (sigmoid, tanh, ReLU). For large enough this is a universal approximator — but so are trees and boosting; the win is when the truth is itself a function of functions (vision, where CNNs wrap local structure into abstractions — the organized-data point: pixel locations carry information a flat model throws away).
- Score + search: squared error (or cross-entropy), minimized by gradient descent. The criterion is convex in the output weights but not in the hidden weights ⟹ many local minima, sensitivity to initialization. This non-convexity (vs logistic regression’s single optimum, 06a §5) is the price of the extra flexibility — and what makes NNs unstable (and thus baggable).
- Backpropagation — the gradient by the chain rule. Per-example squared-error cost , with and , . Differentiate layer by layer. Output weight (chain through ): Input weight sits deeper — the dependence runs , so the chain rule is a product of four factors: Evaluate the four factors one at a time (the third uses the sigmoid identity ): Multiply them back together: Read it right to left as the network error, routed to node by its outgoing weight (node ‘s share of the error), bent by the local slope , and attributed to input in proportion to . Each node needs only its local share ⟹ fully parallelizable. Training = forward pass (propagate signal to output) + backward pass (propagate error-shares to weights).
- Stochastic / online gradient descent with momentum (): smooths the noisy per-example gradient (a decaying-average of recent gradients), damping the zig-zag in elongated valleys. Small early (any step helps far from the optimum), larger later.
- Regularization is essential (NNs overfit by construction). Weight decay = an explicit L2 penalty (ridge on the weights). Early stopping = implicit regularization: monitor validation error and stop when it turns up — equivalent to penalizing the number of steps. Dropout = bagging-by-sampling-units.
- Basis-function reading: — NNs are adaptive basis expansions (06a §7), the basis learned rather than fixed. The radial basis function is the alternative that varies in all directions (concentric bumps) — ideal for isolated peaks where a sigmoid net struggles.
Implications
- The structure/score/search frame makes NNs un-mysterious: a flexible adaptive-basis class, a standard loss, and gradient search — the novelty is depth (functions of functions) and the engineering of the search.
- Non-convexity is the defining tradeoff: NNs trade logistic regression’s guaranteed optimum for representational power, which is why they need the most data, the most regularization, and restarts.
- “Treat organized data as organized” (use pixel locations via convolution) is the conceptual bridge to modern deep learning (track 11).
Core competency set
- Write the one-hidden-layer model and explain universal approximation + the win condition (function-of-functions).
- Derive the backprop gradients and read them as error-shares; explain momentum.
- Contrast weight decay vs early stopping as regularization; place RBF vs sigmoid.
5. Support vector machines and kernels
- Maximal margin classifier: with separable labels and a separating hyperplane (), maximize the margin : is the signed distance (positive when correct); the widest “slab” between the classes. Equivalently s.t. (set ). The solution depends only on the points on the margin — the support vectors. Picture to hold: the widest slab you can slide between the two classes; only the points touching its faces hold it in place — slide an interior point around and the boundary doesn’t move.
- Support vector classifier (soft margin): allow violations with slack , budget : : inside the margin; : misclassified. Larger budget ⟹ wider margin, more support vectors, more bias / less variance — (or its dual ) is the regularization knob, set by CV.
- Why the solution is sparse in the data — Lagrangian sketch. Attach multipliers to the margin constraints . Stationarity of the Lagrangian in gives so the normal vector is a linear combination of the training points. The KKT complementary-slackness condition forces for every point strictly outside the margin (its constraint is slack) — so only points on the margin (the support vectors) have and enter .
- The kernel trick. Substituting back, the classifier depends on the data only through inner products, with only for support vectors. Replace by a kernel — an inner product in some (possibly infinite-dimensional) feature space — and you get a nonlinear boundary at linear cost. A linear boundary in the enlarged space is nonlinear in the original. Polynomial ; radial (infinite-dimensional feature map, yet computable). Valid kernels are exactly the positive-semidefinite ones (Gram matrix PSD); sums/products of kernels are kernels.
- SVM as loss + penalty. The SVC is equivalent to hinge loss + ridge penalty. The hinge is a kinked, convex surrogate for 0–1 loss; logistic’s is a smooth version of the same shape. So SVM and logistic regression differ mainly in the loss kink — as on separable data they give the same boundary.
- When which: SVM behaves better when classes are well-separated and for (data is then separable); logistic is preferred in overlapping regimes, gives probabilities, and extends to multiclass more naturally (SVM multiclass is one-vs-one / one-vs-all hacks).
- The kernel idea generalizes: any method depending only on inner products (PCA → kernel PCA, ridge, etc.) can be kernelized — replace with .
Implications
- The hinge-loss-+-penalty view places SVM in the same family as ridge/lasso/logistic (06a §3, §5): a convex loss plus a shrinkage penalty, tuned by CV — demystifying the “margin” mystique.
- The kernel trick is the deepest idea here: nonlinearity for free wherever an algorithm touches data only through inner products — and it built a decade of nonparametric methods.
- Support-vector sparsity (only boundary points matter) is the classification echo of the lasso’s “few things matter.”
Core competency set
- Write the hard- and soft-margin programs and the reformulation; define support vectors and the role of .
- State the kernel trick (inner-product dependence → replace with ) and the PSD validity condition; give polynomial/radial kernels.
- Write SVM as hinge + ridge and compare hinge vs logistic loss.
6. Unsupervised learning
No labels — find structure: a low-dimensional representation (PCA, manifold methods) or homogeneous groups (clustering).
- PCA — derived. The first principal component is the unit direction of maximal projected variance: Enforce the unit-norm constraint with a multiplier :
Differentiate, using ( symmetric) and , and set to zero:
Divide by 2 — that is the eigenvector equation:
On an eigenvector the objective reads , so maximizing projected variance means taking the largest eigenvalue — is the top eigenvector of . Later PCs are the next eigenvectors (add to the same Lagrangian). Equivalently the SVD of centered : right singular vectors = loadings, = variances; scores are the data in the new basis.
- Two readings: directions of maximal variance, and the affine subspace closest to the data (the first PCs give the best rank- Euclidean approximation). PVE of component = its eigenvalue / total variance; scree plot to choose . Scale-dependent ⟹ standardize unless units match. Unique up to sign.
- K-means. Minimize within-cluster scatter (twice the sum of squared distances to centroids). Lloyd’s algorithm: alternate (a) assign each point to the nearest centroid, (b) recompute centroids. Each step is non-increasing ⟹ converges, but to a local minimum (restart from several seeds). Works best on convex, equal-sized clusters. (It is a degenerate Gaussian-mixture / EM limit — track 7 §7.)
- Hierarchical (agglomerative) clustering: start with singletons, repeatedly merge the two least-dissimilar clusters; the merge height in the dendrogram is the dissimilarity. Linkages: complete (max pairwise — compact clusters), single (min — chaining), average, centroid (can invert). Read similarity by merge height, not horizontal proximity. Correlation-based distance groups by pattern regardless of magnitude. Best when clusters are genuinely nested.
- Nonlinear dimension reduction (high signal-to-noise manifolds — the “Swiss roll”):
- Kernel PCA: PCA on — captures nonlinear variation (e.g. concentric circles a linear PCA can’t separate).
- MDS: find low-D points preserving pairwise distances, .
- Isomap: MDS on geodesic distances (shortest paths in a nearest-neighbor graph) — unrolls the manifold.
- LLE: reconstruct each point from its neighbors (), then find low-D preserving the same weights. LLE/Isomap reduce to kernel PCA with particular kernels.
Implications
- PCA, kernel PCA, and the SVD-shrinkage methods of 06a §3 are one linear-algebra family — eigen/SVD structure of a covariance or kernel matrix, used to compress, denoise, or regularize.
- Clustering decisions (distance, , scaling, linkage) are modeling choices with no labels to check against — results are exploratory, not validated; this is the defining caution of unsupervised work.
- Manifold methods all assume the data lives near a low-dimensional surface with high signal-to-noise; raise the noise and the structure dissolves.
Core competency set
- Derive PC1 as the top eigenvector of the covariance; give both readings and PVE.
- State the K-means objective and Lloyd’s algorithm; explain the local-minimum issue.
- List the linkages and how to read a dendrogram; sketch what Isomap/LLE/kernel-PCA each do.
7. Missing data and the meta-frame
- Missingness mechanisms (the distinction that dictates what’s valid):
- MCAR (completely at random): missingness ⊥ everything — dropping rows is unbiased, just wasteful.
- MAR (at random): missingness depends only on observed variables — recoverable by conditioning/imputation.
- MNAR (not at random): missingness depends on the missing value itself (high earners hide income; censoring) — not fixable without a model of the mechanism.
- Adjustments: treat “missing” as a category; CART surrogate splits (§1); single imputation (mean/median/regression-on-other-predictors — biases variances down, understates uncertainty); multiple imputation (impute many times from a model, pool — propagates uncertainty); iterative imputation (cycle, imputing each variable from the rest — backfitting again). Bootstrap the whole imputation pipeline to get honest SEs.
- Low-rank matrix completion (Netflix). is a projection onto , so the column space is what matters; if the data matrix is approximately low rank, fill missing entries from a rank- approximation: over observed entries . Solve by hard-impute (fill, SVD-truncate, refill, repeat) or the convex nuclear-norm relaxation — the SVD analogue of the lasso (penalize singular values ⟹ low rank), inversely controlling rank.
- The meta-frame — choosing a method at all.
- No free lunch: averaged over all possible target functions, no method beats any other. Performance is about situations — the (unknown) target, the sample size, and the signal-to-noise ratio. Large noise ⟹ restricted methods (more bias, less variance); high signal + large ⟹ flexible methods (KNN, NNs) shine.
- Bet on sparsity: “use a procedure that does well in sparse problems, because no procedure does well in dense problems.” With many predictors, assume few matter — it’s the only regime where you can win, so design for it (lasso, boosting, trees).
- Comparison caution: published method comparisons are biased — selection effects (papers appear when the new method wins), expert bias (the author tunes their own method best). Trust CV on your data over leaderboards.
Implications
- The MCAR/MAR/MNAR ladder tells you whether a fix exists before you reach for one — MNAR needs a mechanism model no imputation can supply.
- Matrix completion ties the whole course together: projection (06a §3), low-rank/SVD (track 2), and the lasso’s convex-relaxation trick (nuclear norm) in one method.
- “No free lunch + bet on sparsity” is the honest summary of the entire two-part guide: there is no best method, only a best match to the situation, and the situations worth betting on are sparse.
Core competency set
- Define MCAR/MAR/MNAR and which admit a fix; contrast single vs multiple imputation.
- State low-rank completion and the nuclear-norm relaxation as the SVD-lasso.
- State no-free-lunch and bet-on-sparsity and what they imply for method choice.
8. Memorize cold
- Tree: ; greedy split minimizes child RSS; Gini = squared-error-on-probabilities (misclassification not smooth enough to split on); cost-complexity , prune + CV.
- Bagging: average deep unpruned trees, ; OOB = free test error. RF: split on random predictors to decorrelate; ⟹ bagging.
- Boosting: generalized residual (= residual for L2, sign for L1); MART = fit tree to for regions, re-optimize each leaf , update ; tree depth = interaction order (stump = additive); partial dependence = average over other vars.
- NN: ; backprop ; non-convex in ; regularize by weight decay (L2) or early stopping.
- SVM: s.t. , ; s.t. margin ; depends on ⟹ kernel trick (PSD ); hinge + ridge.
- PCA: PC1 = top eigenvector of covariance = ; = SVD of centered ; PVE = eigenvalue share.
- K-means: minimize within-cluster SS, Lloyd alternation, local min (restart). Hierarchical linkages: complete/single/average/centroid; read merge height.
- Missing: MCAR (drop ok) / MAR (impute) / MNAR (need mechanism); multiple imputation propagates uncertainty; low-rank completion + nuclear-norm = SVD-lasso.
- No free lunch (performance is situational); bet on sparsity.
Named moves (cross-track glossary): greedy-recursive-partition (CART); differentiable-surrogate-for-a-nonsmooth-loss (Gini for misclassification, hinge for 0–1); average-to-kill-variance (bagging/forests/dropout); decorrelate-then-average (random forests); fit-the-(generalized)-residual (boosting); function-space-gradient-descent (MART); back-propagate-the-error-share (NN backprop); kernel-trick = replace-inner-products (SVM, kernel PCA — track 2); convex-relaxation (L0→L1 lasso, rank→nuclear-norm); bet-on-sparsity (whole course).