PythiloLesson 6 of 12 · progress kept in this browser

Ridge Regression

A closed-form one-feature ridge fit shrinks the slope. Centre the data so the intercept is not penalized; lambda zero recovers least squares.

numerator, spread = 4, 2
print(numerator / spread)
print(numerator / (spread+2))
Your task

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.