Top: data + fitted curve at current λ · Bottom: real re-fitted CV error vs λ

Cross-Validation Lambda Tuner: Ridge Regression (2D)

Choosing a regularization strength by eyeballing the training fit is a trap — training error only ever improves as a model gets more flexible. This simulator makes k-fold cross-validation visible in plain 2D: forty-eight noisy points are generated from a fixed nonlinear function, a ridge-regularized polynomial is fit at whatever λ you drag the slider to, and a second panel recomputes the true cross-validation error curve by genuinely splitting the data into K folds, refitting on K−1 of them and scoring on the one held out, at 60 log-spaced candidate λ values. The gold dot marks the λ that minimizes mean validation error — drag your own slider toward it, or away from it, and watch the fitted curve swing between underfitting (too stiff) and overfitting (chasing noise).