WRITE · TRACE · UNDERSTAND
Ridge Regression
A closed-form one-feature ridge fit shrinks the slope.
Your experiment
ridge(xs, ys, penalty) returns (slope, intercept) minimizing sum squared error + penalty*slope**2. Inputs are nonempty and penalty >= 0. Return slope zero when the denominator is zero.
Python runs in your browser. Your draft stays on this device.
What to look for
A closed-form one-feature ridge fit shrinks the slope. Centre the data so the intercept is not penalized; lambda zero recovers least squares.
Watch your code work
Ready to experimentWrite a solution or load the worked answer, then choose Trace & check.
Step through arrays, variables and training curves produced by your own Python.