Shrunken Slopes
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
- 4 to 40 rows, 1 to 3 columns
0.1 <= alpha <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More scikit-learn problems
- Two Main DirectionsMedium
- Words to CountsMedium
- How Many GroupsHard
- Keep the Useful ColumnsHard
- Leak-Free ScoreHard
- Mixed ColumnsHard
- Pick the PenaltyHard
- Right Amount of BendHard