wanna mathMath ain't scary (not anymore)
4-Tier Textbook Index • Vol → Mod → Ch → Lab

Engineering Mathematics Volumes I–VI

6 Volumes • 20 Modules • 85 ChaptersFull Matrix →
4-Tier Statistics Index • Vol S → Mod → Ch → Lab

Interactive Statistics (S.1–S.6)

6 Modules • 18 ChaptersStatistics Index →
CHAPTER S.6.2 • 2D + 3DPublished Interactive Labs~35 min study

Multiple Linear Regression (3D), Diagnostics & Ridge/Lasso Shrinkage

Fit a 3D regression plane to two predictors and see geometrically why Lasso's L₁ diamond snaps coefficients to zero while Ridge's L₂ circle shrinks smoothly.

Engineering & Physical Application Context

Multivariable predictive modeling, multicollinearity prevention, feature selection, and preventing overfitting via cross-validation.

Governing Mathematical Formulation
β^=(XTX)−1XTy,Ridge (L2) vs. Lasso (L1)\hat{\boldsymbol{\beta}} = (X^T X)^{-1}X^T\mathbf{y}, \qquad \text{Ridge } (L_2) \text{ vs. Lasso } (L_1)
Volume S • Module S.61 Interactive Lab(s)

The Question You Should Ask

Why do collinear features destabilize normal equations (XTX)−1XTy(X^T X)^{-1}X^T\mathbf{y}—and why do Lasso's L1L_1 diamond corners set coefficients cleanly to zero while Ridge's L2L_2 sphere shrinks them together?

In Simple Words & Math

When columns of XX correlate tightly, XTXX^T X becomes nearly singular and stretches elliptical RSS contours diagonally—sending unregularized OLS weights swinging wildly across samples.

Adding a penalty λ∥β∥22\lambda\|\boldsymbol{\beta}\|_2^2 (Ridge) stabilizes inversion with circular symmetry, whereas Lasso's sharp L1L_1 constraint ∣β1∣+∣β2∣≤t|\beta_1|+|\beta_2| \le t meets expanding loss ellipses cleanly on coordinate axes.

4-Step Pedagogical Chapter Rhythm • Geometric Intuition First
Ch. S.6.2
STEP 1 • GEOMETRIC QUESTION

Why does adding correlated features blow up OLS weights—and why does changing β₁² + β₂² to |β₁| + |β₂| suddenly perform automatic feature selection?

STEP 2 • INTERACTIVE LAB EXPLORATION

Orbit the 3D regression plane ŷ = β₀ + β₁x₁ + β₂x₂ with residual drop-lines while scrubbing regularization λ to watch RSS ellipses hit Ridge's circle vs. Lasso's sharp diamond corners.

STEP 3 • SYMBOLIC FORMALIZATION
β^OLS=(XTX)−1XTy,min⁡β∥y−Xβ∥22+λ∥β∥pp\hat{\boldsymbol{\beta}}_{\text{OLS}} = (X^T X)^{-1} X^T \mathbf{y}, \qquad \min_{\boldsymbol{\beta}} \|\mathbf{y} - X\boldsymbol{\beta}\|_2^2 + \lambda \|\boldsymbol{\beta}\|_p^p
STEP 4 • EDGE CASES & NEXT BRIDGE

Regularization shrinks noisy estimates toward stability; our final chapter S.6.3 unites Bayesian prior-to-posterior updating with computer-age Bootstrap resampling.

Interactive Laboratories in Chapter S.6.2
FIRST-TIMER GUIDE • 3D PLANES, MULTICOLLINEARITY & REGULARIZATION

Fitting a 3D Plane to Two Predictors—And Why Lasso's Diamond Snaps Useless Weights to Exact Zero

With two predictors (x1,x2x_1, x_2), OLS no longer fits a line—it tilts a rigid 3D plane (y^=β0+β1x1+β2x2\hat{y} = \beta_0 + \beta_1 x_1 + \beta_2 x_2) to minimize vertical drop-lines! Trouble strikes when x1x_1 and x2x_2 move together (multicollinearity): OLS gets confused about who deserves credit and explodes into +50x1−49x2+50 x_1 - 49 x_2, failing badly on new test data. Adding a penalty λ\lambda shrinks weights smoothly toward stability—and changing the budget shape from a smooth Ridge Circle to a pointy Lasso Diamond makes ellipses hit a corner and kill redundant features!

Initializing Interactive Laboratory
LOADING MODULE

Preparing interactive canvas & numerical solver…

wanna math drafting viewport

Normal Equations Projection, Multicollinearity & Ridge vs. Lasso Geometry

1. NORMAL EQUATIONS PROJECTION
β^OLS=(XTX)−1XTy\hat{\boldsymbol{\beta}}_{\text{OLS}} = (X^T X)^{-1} X^T \mathbf{y}

Directly from Linear Algebra (2.2.3): y^=Xβ^\hat{\mathbf{y}} = X\hat{\boldsymbol{\beta}} is the orthogonal shadow of y\mathbf{y} onto Col⁡(X)\operatorname{Col}(X)! When x1≈x2x_1 \approx x_2, XTXX^T X becomes nearly singular and its inverse explodes.

2. RIDGE (L₂) VS. LASSO (L₁) CORNERS
min⁡β  ∥y−Xβ∥22+λ∥β∥pp\min_{\boldsymbol{\beta}} \;\|\mathbf{y} - X\boldsymbol{\beta}\|_2^2 + \lambda \|\boldsymbol{\beta}\|_p^p

A Ridge Circle (p=2p=2) is smoothly round, so ellipses touch off-axis and shrink coefficients evenly without zeroing. A Lasso Diamond (p=1p=1) has sharp vertices sitting right on β1=0\beta_1 = 0 or β2=0\beta_2 = 0—causing automatic sparse feature selection!

3. TINY WORKED TRAIN VS. TEST CHECK

Notice in the 3D footer readout: adding noise predictors ALWAYS raises Train R2R^2, even while Test CV R2R^2 drops!

Radj2=1−SSE/(n−p−1)SST/(n−1)R^2_{\text{adj}} = 1 - \frac{\text{SSE}/(n - p - 1)}{\text{SST}/(n - 1)}

Always tune λ\lambda using held-out Cross-Validation, never raw training R2R^2!

TRAP • STANDARDIZE FEATURES BEFORE REGULARIZING!

Never apply λ(β12+β22)\lambda(\beta_1^2 + \beta_2^2) if x1x_1 is in millimeters and x2x_2 is in kilometers—unit scaling changes β\beta magnitudes! Convert every predictor to ZZ-scores first.

BRIDGE TO S.6.3 • THE BAYESIAN SECRET BEHIND RIDGE!

Cool mathematical plot twist: adding Ridge penalty λ∥β∥22\lambda \|\boldsymbol{\beta}\|_2^2 is mathematically identical to placing a zero-centered Gaussian prior β∼N(0,τ2I)\boldsymbol{\beta} \sim \mathcal{N}(0, \tau^2 I) in Bayesian Inference (S.6.3)!

High-Dimensional Regression • Ch. S.6.2

Projection Normal Equations, Collinearity VIF & Geometry of Ridge vs. Lasso

Open Ridge/Lasso Formulas →
1. NORMAL EQUATIONS & HAT PROJECTION
XT(y−Xβ^)=0  ⟹  β^=(XTX)−1XTyX^T(\mathbf{y} - X\hat{\boldsymbol{\beta}}) = \mathbf{0} \implies \hat{\boldsymbol{\beta}} = (X^T X)^{-1}X^T\mathbf{y}

Fitted values y^=Hy\hat{\mathbf{y}} = H\mathbf{y} are the literal orthogonal shadow of y\mathbf{y} onto the column plane Col⁡(X)\operatorname{Col}(X), with trace tr⁡(H)=p+1\operatorname{tr}(H)=p+1 measuring effective model degrees of freedom.

2. WHY COLLINEARITY BLOWS UP β̂
Var⁡(β^j)=σ2SSTj 11−Rj2⏟VIFj\operatorname{Var}(\hat{\beta}_j) = \frac{\sigma^2}{\text{SST}_j}\,\underbrace{\frac{1}{1 - R_j^2}}_{\text{VIF}_j}

If predictor x2≈x1x_2 \approx x_1 (Rj2=0.98  ⟹  VIF=50R_j^2 = 0.98 \implies \text{VIF}=50), tiny eigenvalue λmin⁡(XTX)\lambda_{\min}(X^T X) stretches the loss valley into a narrow trench where β^1\hat{\beta}_1 and β^2\hat{\beta}_2 explode in opposite signs.

3. RIDGE CIRCLE VS. LASSO DIAMOND SPARSITY
β^Ridge=(XTX+λI)−1XTyvs.∥β∥1≤t\hat{\boldsymbol{\beta}}_{\text{Ridge}} = (X^T X + \lambda I)^{-1}X^T\mathbf{y} \quad \text{vs.} \quad \|\boldsymbol{\beta}\|_1 \le t

Adding λI\lambda I lifts every tiny eigenvalue cleanly away from zero. In (β1,β2)(\beta_1,\beta_2) space, tilted RSS ellipses tangent to an L2L_2 disk hit non-zero weights, whereas L1L_1 diamond corners snap coordinates onto exact zeros!

Chapter S.6.2 Laboratory Specifications

1 Interactive Lab(s)
LAB S.6.2.1Component: MultipleRegression3DRegularizationLab

3D Multiple Regression Plane & Ridge/Lasso Contour Lab

Orbit a 3D OLS plane and watch elliptical RSS contours intersect L₂ circles (Ridge) vs. L₁ diamonds (Lasso) as λ grows.

∥y−Xβ∥22+λ∥β∥1\|\mathbf{y} - X\boldsymbol{\beta}\|_2^2 + \lambda\|\boldsymbol{\beta}\|_1