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.
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.
Multivariable predictive modeling, multicollinearity prevention, feature selection, and preventing overfitting via cross-validation.
Why do collinear features destabilize normal equations —and why do Lasso's diamond corners set coefficients cleanly to zero while Ridge's sphere shrinks them together?
When columns of correlate tightly, becomes nearly singular and stretches elliptical RSS contours diagonally—sending unregularized OLS weights swinging wildly across samples.
Adding a penalty (Ridge) stabilizes inversion with circular symmetry, whereas Lasso's sharp constraint meets expanding loss ellipses cleanly on coordinate axes.
Why does adding correlated features blow up OLS weights—and why does changing β₁² + β₂² to |β₁| + |β₂| suddenly perform automatic feature selection?
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.
Regularization shrinks noisy estimates toward stability; our final chapter S.6.3 unites Bayesian prior-to-posterior updating with computer-age Bootstrap resampling.
With two predictors (), OLS no longer fits a line—it tilts a rigid 3D plane () to minimize vertical drop-lines! Trouble strikes when and move together (multicollinearity): OLS gets confused about who deserves credit and explodes into , failing badly on new test data. Adding a penalty 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!
Preparing interactive canvas & numerical solver…
wanna math drafting viewport
Directly from Linear Algebra (2.2.3): is the orthogonal shadow of onto ! When , becomes nearly singular and its inverse explodes.
A Ridge Circle () is smoothly round, so ellipses touch off-axis and shrink coefficients evenly without zeroing. A Lasso Diamond () has sharp vertices sitting right on or —causing automatic sparse feature selection!
Notice in the 3D footer readout: adding noise predictors ALWAYS raises Train , even while Test CV drops!
Always tune using held-out Cross-Validation, never raw training !
Never apply if is in millimeters and is in kilometers—unit scaling changes magnitudes! Convert every predictor to -scores first.
Cool mathematical plot twist: adding Ridge penalty is mathematically identical to placing a zero-centered Gaussian prior in Bayesian Inference (S.6.3)!
Fitted values are the literal orthogonal shadow of onto the column plane , with trace measuring effective model degrees of freedom.
If predictor (), tiny eigenvalue stretches the loss valley into a narrow trench where and explode in opposite signs.
Adding lifts every tiny eigenvalue cleanly away from zero. In space, tilted RSS ellipses tangent to an disk hit non-zero weights, whereas diamond corners snap coordinates onto exact zeros!
Orbit a 3D OLS plane and watch elliptical RSS contours intersect L₂ circles (Ridge) vs. L₁ diamonds (Lasso) as λ grows.
Increase penalty λ to watch the constraint boundary shrink—and notice when RSS ellipses kiss a sharp Lasso corner!
Crank Collinearity to 0.90: the OLS ellipse stretches diagonally! snaps cleanly at its diamond corner, while splits weight smoothly across both features.