FunctionRacerProblemsRace

Shrunken Slopes

Mediumscikit-learnPython

Ridge regression is least squares with a penalty on large slopes: the bigger alpha, the more the slopes are pulled toward 0. Fit a ridge regression of y on X with the given alpha and return its slopes.

Example 1

X [[1],[2],[3],[4]]
y [3,5,7,9]
alpha 5.0
returns [1.0]

Least squares would give a slope of 2. With alpha = 5 it shrinks to 1.

Example 2

X [[-1],[1]]
y [-4,4]
alpha 2.0
returns [2.0]

Least squares would give 4. Here it is halved.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More scikit-learn problems