Statistical Learning I
Supervised learning is an impossible problem made tractable by restriction: any function passing through the training points has zero training error, so without a constraint on the class of functions there is nothing to learn. Every method is therefore a triple — a structural model (the function class), a score (the loss it minimizes), and a search (how it optimizes) — and the whole subject is choosing a restriction matched to the unknown truth. One tradeoff governs all of it: bias vs variance, with the curse of dimensionality the reason local methods need help. This first half builds the frame, then the restrictions that are smooth — linear models, shrinkage, generative and discriminative classifiers, and basis expansions — plus the machinery to assess any of them. The algorithmic restrictions (trees, ensembles, margins, unsupervised structure) are the second half, [[06b_Statistical_Learning_II]]. Prerequisites cashed in: projection, SVD, eigendecomposition (track 2); MLE, CLT, bias–variance, sufficiency (track 3); priors and ridge/lasso-as-MAP (track 7 §3).
1. The frame: what we estimate and why we must restrict
- The data model: , with and . Two goals pull in opposite directions — prediction (treat as a black box, only matters) and inference (understand how drives , so must be interpretable). Restrictive models serve inference; flexible models serve prediction.
- The regression function is the conditional mean — derived. Under squared-error loss the expected prediction error of any is Minimize pointwise: for fixed , choose the constant minimizing . Differentiate in : . So
the regression function — the best possible predictor under squared error. (Absolute-error loss instead gives the conditional median — more robust.)
- The Bayes classifier — derived from 0–1 loss. For classification with loss matrix , the risk of predicting at is . Under 0–1 loss this is , minimized by Predict the most probable class. Its error rate is the Bayes rate — the classification analogue of irreducible error , a floor no method can beat.
- Why restriction is forced. Minimizing over all functions has infinitely many solutions — any interpolating the points scores zero. Useless: under a fresh sample with different noise, an interpolator errs everywhere. We must shrink the class of admissible . Almost every restriction is some form of smoothness — “the function is roughly constant in small neighborhoods” — imposed explicitly (linearity, splines) or implicitly (the neighborhood size in KNN).
- KNN as the canonical local estimator. Approximate the conditional mean by a local average: the nearest training points. As and this converges to — KNN is universal. Its effective number of parameters is (imagine non-overlapping neighborhoods, one mean each), so small = flexible.
Implications
- The conditional mean is the target every regression method is trying to estimate; methods differ only in how they approximate it (global linear fit vs local average vs basis expansion).
- The Bayes classifier and the regression function are the same idea — best pointwise prediction — and both are unattainable (we don’t know ); methods are estimates of them.
- “No restriction ⟹ interpolation ⟹ zero training error ⟹ useless test error” is the seed of overfitting and of the entire bias–variance story (§2).
Core competency set
- Derive from squared-error EPE; state the L1 analogue.
- Derive the Bayes classifier from 0–1 loss; relate the Bayes rate to irreducible error.
- Explain why unrestricted RSS minimization fails and name smoothness as the usual fix.
2. Bias, variance, and the curse of dimensionality
- The decomposition — derived. Test point , , with fresh noise independent of the training-set estimate . Insert and expand:
Middle term (, ), leaving . Insert and expand again:
Middle term (). So
Flexibility trades the last two: flexible ⟹ lower bias, higher variance.
- KNN bias–variance, explicitly. With , Variance falls as grows; bias grows as the neighborhood widens off . (If is linear and the neighborhood symmetric, the average is unbiased — bias is a curvature/asymmetry effect.)
- OLS vs 1-NN — the worked comparison. Condition on the training ‘s, so with . The fit’s average variance:
OLS pays ; 1-NN pays a full (one noisy neighbor):
When the linear model is even approximately right, — if the linear model is correct, KNN does much worse.
- The curse of dimensionality. To capture a fraction of uniform data in a -cube needs edge length
At , : — you span 80% of every coordinate. “Local” is no longer local: a neighborhood holding any useful fraction is nearly the whole space, so a local average is secretly global and KNN’s bias creeps back. Most points also sit near the boundary, and density falls as . Any method averaging over small isotropic neighborhoods is cursed.
Implications
- Bias–variance is the master dial: every tuning parameter (the in KNN, in ridge, tree size, spline df) is a point on this tradeoff, chosen to minimize test error not training error.
- The curse is why we bother with structured models: a global linear fit doesn’t need local neighborhoods, so it sidesteps the dimensionality explosion at the cost of bias.
- The OLS- vs 1-NN- comparison is the quantitative case for parametric models in low-data / high-noise / sparse regimes.
Core competency set
- Derive the bias–variance decomposition (both cross terms dying) and the KNN special case.
- Reproduce the OLS variance and the 1-NN , and state the conclusion.
- Compute for a concrete and state the three faces of the curse.
3. Linear methods and shrinkage
Least squares as projection.
- Model — linear in the parameters, any transform. Minimize . Differentiate:
Set to zero — the normal equations, which say the residual is orthogonal to the columns:
So is the orthogonal projection of onto , with hat matrix (symmetric, idempotent, ). Rank-deficient : is still the projection, only is non-unique.
- Solve by QR, not by inverting . Since orthogonal preserves norm, gives
The first term is zeroed by (a triangular solve, numerically stable); the second is the irreducible , and .
- Add Gaussian errors and , unbiased for , and the coefficient -statistics and the -test for nested models follow (cross-link track 4).
- Gram–Schmidt reading. Regressing on orthogonalized predictors gives , where is with the other predictors regressed out. So — correlated predictors shrink and inflate the variance, the seed of collinearity trouble (VIF, track 4).
- Equivariance. OLS is equivariant under nonsingular linear reparametrization of ( transforms back exactly). PCA, ridge, and lasso are not — which is why they require standardizing the inputs.
Gauss–Markov, derived. Among all linear unbiased estimators of an estimable , OLS has minimum variance (BLUE). Proof: any linear estimator is ; unbiasedness for all forces . The OLS estimator has weight , which lies in ; split any competitor as , where (both satisfy the same constraint , so ). Then with equality iff . Off-subspace mass is pure variance cost — the same split-orthogonally-and-drop move as the projection itself.
- The loophole. Unbiasedness is a self-imposed restriction: a biased estimator can have smaller MSE. Since , shrinking coefficients toward zero can shrink the variance faster than it grows the bias (James–Stein) — the entire motivation for the shrinkage methods below.
Ridge regression.
- , equivalently constrain . Centered , solve by setting the gradient to zero: Adding makes the system always invertible — ridge fixes the singularity of as a bonus.
- SVD reveals what it does — derive it. Write , so . Because , write and combine inside one :
With , the in the middle cancels:
Push through to fitted values ; another cancels and the diagonal factors combine entrywise:
Ridge projects onto each left singular vector and shrinks that coordinate by — small- (low-variance) directions are shrunk hardest. It implicitly assumes the response varies most where the inputs vary most. Effective df: ranging from (at ) to (as ). Orthonormal : — uniform scaling. Numbers: with singular values and , the shrinkage factors are , , — the strong direction barely touched, the weak (noisy) direction nearly erased; df .
Lasso.
- , equivalently . The L1 penalty sets coefficients exactly to zero — simultaneous shrinkage and selection, a convex relaxation of best-subset’s L0 count.
- Soft thresholding — derived (orthonormal case). With orthonormal columns the objective separates coordinatewise into
where is the OLS coordinate (the cross term drops because the OLS residual is orthogonal to ). Minimize over by cases on its sign, since has a kink at :
- : differentiable, — feasible only if .
- : symmetrically — feasible only if .
- : neither branch is feasible, so the minimum sits at the kink, .
Stitch the cases into one expression:
Contrast ridge’s proportional shrinkage : lasso translates toward zero and truncates. Numbers (): (shrink the survivor); (kill the small one). Ridge at would instead give and — nothing zeroed.
- : the smallest killing all coefficients equals — the first variable to enter is the most correlated with . The path is piecewise linear (LARS), computable in one OLS-cost sweep. Active-set variables satisfy .
- The geometry. Elliptical RSS contours first touch the constraint region at the optimum. The L2 ball is a disk (touch point generically off-axis ⟹ no zeros); the L1 ball is a diamond with corners on the axes (touch point often at a corner ⟹ a zero). In high dimensions the diamond has many corners — sparsity is generic.
Choosing among them.
- All coefficients nonzero ⟹ ridge wins (lower variance, similar bias). Few nonzero (sparse truth) ⟹ lasso wins. Elastic net interpolates: it produces zeros like lasso but averages correlated groups like ridge (lasso arbitrarily picks one of a correlated pair; ridge splits the weight).
- Bayesian reading (track 7 §3): ridge = posterior mode under a Gaussian prior, lasso = under a Laplace prior, best-subset = under a spike-at-zero prior. Every penalty is a log-prior; is the power family ().
Derived-direction methods.
- PCR: regress on the first principal components (the eigenvectors of , or the SVD right vectors). Unsupervised — directions chosen by input variance, blind to . In the SVD basis PCR keeps components at full weight and discards the rest; ridge keeps all but shrinks smoothly by — PCR is a hard-threshold cousin of ridge.
- PLS: supervised — directions with high variance and high correlation with (regress on each , weight by the coefficients, form , orthogonalize, repeat). Variance usually dominates, so PLS behaves much like PCR/ridge. Equivalent to OLS after steps.
Implications
- Ridge/lasso/PCR/PLS all operate through the SVD of — they are different shrinkage profiles on the principal coordinates (smooth, threshold-at-zero, hard-cut, -weighted). Seeing them as one family is the payoff.
- Shrinkage beats best-subset on noisy data because subset selection is a discrete search (high variance); continuous shrinkage is stable. Subset df overcounts (it spends df hunting and keeps coefficients unshrunk).
- For prediction, ridge is the safe default; lasso when you also want a short interpretable list; elastic net when predictors come in correlated groups.
Core competency set
- Derive the normal equations and the projection/QR forms; state the Gram–Schmidt variance .
- Derive ridge’s SVD shrinkage and its df; derive lasso soft-thresholding and contrast with ridge.
- State , the L1-vs-L2 geometry, and the ridge↔PCR SVD relationship.
- Give the penalty↔prior dictionary and place elastic net.
4. Classification I — generative (density) methods
Model the class-conditional densities, then invert with Bayes. The prior is , the density , and
LDA — derived. Model each class as multivariate Gaussian with a common covariance, . Compare two classes by the log posterior-ratio, which by Bayes splits into a prior part and a density part:
The Gaussian log-density is , where is the same for every class (shared ) and so cancels in the ratio. Expand the surviving quadratic:
The leading is identical for and — again because is shared — so it cancels in the difference, and only terms linear in remain:
Linear in ⟹ linear decision boundaries. Reading off the per-class piece gives the discriminant function
Plug in , class mean, and the pooled covariance .
- Picture to hold: the discriminant direction is a skew projection — the presence of tilts it off the line joining the means so that the projected Gaussians overlap as little as possible.
QDA: drop the common-covariance assumption; the quadratic terms survive ⟹ quadratic boundaries. Cost: a separate per class (many parameters when is large). Regularized DA shrinks toward the pooled (parameter : QDA, LDA), and the pooled toward a scalar — a ridge for covariance.
Fisher / reduced-rank LDA. The class centroids span an affine subspace of dimension ; since classification depends only on distances to centroids (in the metric), project onto that subspace — free dimension reduction. Fisher’s criterion: find maximizing between-class over within-class variance, = between-class, = pooled within-class covariance. Reformulate as s.t. — a generalized eigenvalue problem (whiten by , then ordinary PCA on the centroids). The leading discriminant coordinates often separate the classes in 2–3 dimensions for visualization.
Shrunken centroids (the wide-data classifier, ). Standardize each class-centroid deviation from the overall centroid by the pooled within-class SD, then soft-threshold it (lasso again): deviations below collapse to zero, removing that gene/feature from that class’s rule. The discriminant becomes with shrunken centroids . Performs feature selection LDA can’t.
Naive Bayes. Assume the within-class features are independent: . High bias, low variance — and for classification you can tolerate a lot of bias (you only need the argmax right). It is exactly a GAM on the logit: , fit by densities rather than likelihood.
Generative vs discriminative. LDA models the full joint (assumes Gaussians); logistic regression (§5) models only the conditional , leaving arbitrary. Same linear-logit form, different estimation:
- LDA has lower variance when the Gaussian assumption holds (it uses more structure), but is non-robust to outliers (every point informs ).
- Logistic is more general and robust, the safer default when the densities are non-Gaussian.
Linear regression of an indicator matrix is a third option (one-hot , regress, classify to largest fitted value) but suffers masking: with collinear classes, a middle class can be dominated everywhere and never predicted; up to degree polynomials are needed to fix an artifact LDA doesn’t have. Avoid it for .
Implications
- All of LDA/QDA/naive Bayes/shrunken-centroids are the same Bayes-rule skeleton with different density assumptions — the assumption is the bias–variance knob (common → linear/low-variance; per-class → quadratic/higher-variance; independence → highest bias).
- LDA’s robustness track record despite non-Gaussian data is the recurring lesson: the data often only supports a simple boundary, and the stable Gaussian estimate beats fancier alternatives.
- Shrinkage reappears here as soft-thresholded centroids — the lasso idea is method-agnostic.
Core competency set
- Derive the LDA discriminant from the Gaussian log-ratio and explain why the boundary is linear; write the pooled .
- State QDA/RDA, the Fisher Rayleigh quotient and its eigen-reformulation, and shrunken centroids.
- Contrast generative vs discriminative (variance/robustness) and describe masking.
5. Classification II — discriminative (logistic regression)
- Model the logit linearly: , equivalently (the logistic squashes into ). The coefficient is a log-odds effect, not a probability effect — depends on .
- Fit by MLE — derive the gradient. Conditioning on , each is Bernoulli with , so the conditional log-likelihood is
Substitute the model (, ); each term collapses to
Differentiate one term, using :
Sum over — the gradient is just the covariate-weighted prediction error:
- The Hessian, and why the problem is concave. Differentiate the gradient; only depends on , and the logistic derivative is (i.e. ):
Every weight , so and is concave — one global maximum, no local traps (contrast the non-convex networks of [[06b_Statistical_Learning_II]] §4).
- Newton’s method is reweighted least squares (IRLS). The Newton update is :
Pull out of the last term by defining the working response ; the update becomes a weighted least-squares fit:
So each step regresses on with weights , then are recomputed and the step repeats — iteratively reweighted least squares. (The weight is the inverse variance of the logit; this is the delta-method bridge to WLS, track 3.)
- Deviance plays the role of RSS: . For nested models, (a , not an — there is no global ). Asymptotically (the inverse Fisher information — track 3).
- Separable-data blow-up. If the classes are linearly separable, the MLE is undefined — to push fitted probabilities to some coefficient must run to . Near-separable data ⟹ exploding variance. The fix is regularization (ridge/lasso logit), which is also required for a solution when .
- Multiclass: model logits against a base class, or use the symmetric softmax (the natural form under a penalty).
Implications
- Concavity is why logistic/Poisson GLMs are reliable workhorses — one optimum, no restarts (contrast the non-convex NNs of [[06b_Statistical_Learning_II]]).
- The IRLS view unifies GLM fitting with weighted least squares: every GLM is “OLS in a loop” on a linearized response.
- Separability is the discriminative twin of the curse: in high dimensions data is usually separable, so regularization is not optional.
Core competency set
- Write the logistic log-likelihood, gradient , and Hessian ; argue concavity.
- Explain IRLS as Newton = weighted least squares; define deviance and the nested test.
- Explain the separable-data blow-up and the regularization need.
6. Model assessment and selection
- The goal is test error, estimated honestly. Training error is biased down and monotone in flexibility — it cannot select models. Two routes: adjust training error analytically, or resample to estimate test error directly.
- Analytic criteria (for a fit with effective parameters, from a low-bias model): /AIC add per parameter (prediction-oriented, asymptotically like CV); BIC adds (heavier ⟹ smaller models, selection-consistent — recovers the true model as ). For non-Gaussian models replace RSS with deviance.
- Cross-validation. Partition into folds; fit on , test on the held-out fold, average. LOOCV () is deterministic and low-bias but high-variance (the training sets are nearly identical ⟹ correlated estimates); or is the usual sweet spot. OLS shortcut (LOOCV without refitting): with the leverage. For model selection, CV chooses the tuning parameter (e.g. subset size); the actual model is then refit on all the data — different folds may pick different subsets of that size, and that’s fine.
- The wrong way to CV — the canonical trap. Proposed: (1) screen all predictors on the full data, keep the 200 most correlated with ; (2) CV a classifier on those 200. With , even pure-noise predictors will correlate with by chance; screening on the full data lets the lucky ones leak into every fold, so CV reports a low error for a model with no real signal. Fix: the entire pipeline — screening included — must happen inside each fold, refit fresh on each training split. Anything done to the data before CV must be CV’d.
- Bootstrap. Resample points with replacement times; the spread of a statistic across replicates estimates its standard error — substituting computation for analytic SEs, and valuable when is random or the SE has no closed form (e.g. SEs after model selection, which the naive formulas get wrong).
- The 1-SE rule. Among models within one standard error of the CV minimum, pick the simplest — bias toward parsimony when the extra complexity buys nothing significant.
Implications
- AIC-for-prediction vs BIC-for-truth is the one-line rule; both are cheap shadows of CV / the Bayesian evidence (track 7 §4).
- “CV the whole pipeline” generalizes far beyond screening — imputation, scaling parameters, feature learning all must live inside the fold or the estimate is optimistic.
- CV estimates have real variance (with small , a null problem can show 20–80% error across runs) — report it, and don’t over-trust a single CV number.
Core competency set
- Write /AIC/BIC/adj- and state the prediction-vs-truth roles.
- Explain LOOCV’s bias/variance, the OLS leverage shortcut, and that CV selects the tuning parameter.
- Reproduce the wrong-way-to-CV failure and the fix; say what the bootstrap buys.
7. Basis expansions and smoothing
Stay linear-in-parameters but enrich : for chosen basis functions (polynomials, indicators, splines, sigmoids). Fitting is still least squares — flexibility without leaving the linear machinery.
- Step functions / piecewise constant: indicators — bin and average. Discontinuous.
- Regression splines. Piecewise cubics joined at knots with continuous value, first, and second derivatives — an order- spline is piecewise degree with continuity up to derivative . The truncated-power basis: each adding a curvature change at knot while preserving the lower-derivative continuity. Natural cubic splines add linearity beyond the boundary knots — spending 4 df to tame the wild polynomial tails (Gibbs/Runge behavior), which can be reinvested as more interior knots. Knots typically at quantiles of ; specify by df and let the data place them.
- Smoothing splines — the penalty route. Instead of choosing knots, put a knot at every and penalize curvature: Remarkably the unique minimizer is a natural cubic spline with knots at the data points — an infinite-dimensional problem with a finite-dimensional solution. In basis form with , giving and a linear smoother .
- Effective df = , monotone in — invert it to specify df directly. ’s eigenvalues are (it shrinks, never amplifies), and the two eigenvalues exactly correspond to the unpenalized constant and linear functions (curvature-free ⟹ no penalty). Each row of is an equivalent kernel — the smoother is a local weighted average in disguise. chosen by (efficient LOO) CV.
- Local regression. Fit a low-degree polynomial at each target weighted by a kernel : . Local linear corrects the boundary bias of local constant (kernel smoothing) — at the edge a kernel reaches asymmetrically, biasing a plain average; the linear fit compensates. Generalizes cleanly to a few dimensions (then the curse bites).
- GAMs — additivity beats the curse: , each a smooth (spline/loess). Flexible per-coordinate, no interactions (the price), interpretable (plot each ). Fit by backfitting (block coordinate descent): cycle, fitting to the partial residual with a smoother, until convergence. For logistic GAMs wrap backfitting in the Newton/IRLS loop.
Implications
- Smoothing splines are ridge for functions: the curvature penalty is an L2 penalty on the spline coefficients, and df = mirrors ridge’s — same shrinkage idea, different basis.
- “Linear in the parameters” is the unifying thread of §3 and §7: splines, polynomials, and indicators all keep you in least-squares-land, so all the §6 assessment machinery applies unchanged.
- GAMs are the sweet spot between linear models and full nonparametrics — they buy flexibility while dodging the dimensionality explosion by forbidding interactions, the same bet trees and boosting will revisit ([[06b_Statistical_Learning_II]]).
Core competency set
- Write the truncated-power cubic-spline basis and say what natural splines fix.
- State the smoothing-spline penalty, its natural-cubic-spline minimizer, and df = .
- Explain local linear’s boundary-bias correction and the GAM backfitting loop.
8. Memorize cold
- minimizes squared-error EPE; Bayes classifier ; Bayes rate = classification irreducible error.
- Unrestricted RSS ⟹ interpolation ⟹ must restrict (smoothness); KNN , eff. params , universal.
- Bias–variance: ; KNN variance .
- OLS variance (= ) vs 1-NN ; curse edge length .
- Normal equations ; projection; QR: ; .
- Ridge ; SVD shrink ; df .
- Lasso soft-threshold ; ; L1 diamond corners ⟹ zeros.
- ridge=Gaussian-prior MAP, lasso=Laplace, subset=L0; PCR hard-thresholds PCs, ridge shrinks them; PLS supervised.
- LDA discriminant ; common ⟹ linear; QDA per-class ⟹ quadratic.
- Fisher: (Rayleigh); shrunken centroids = soft-thresholded LDA.
- generative (LDA, full joint, low-var, non-robust) vs discriminative (logistic, conditional, robust); indicator regression masks for .
- Logistic: , (concave), Newton = IRLS; deviance ; nested ; separable ⟹ MLE blows up.
- ; AIC for prediction, BIC () for truth; LOOCV .
- CV the whole pipeline (screening inside the fold); 1-SE rule; bootstrap for SEs after selection.
- Smoothing spline: minimizer is natural cubic spline at the data; , df ; GAM by backfitting.
Named moves (cross-track glossary): split-orthogonally-and-project (OLS/QR, Gauss–Markov — track 4); trade-bias-for-variance (shrinkage, James–Stein — track 7); shrink-in-the-SVD-basis (ridge/PCR); soft-threshold (lasso, shrunken centroids); recognize-the-shape via Bayes rule (LDA/QDA — track 7); Newton-as-reweighted-least-squares (IRLS); CV-the-whole-pipeline; penalize-curvature (smoothing splines); additivity-beats-the-curse (GAMs).