All problems
Ridge Path Value
Problem
Evaluate the 1D ridge regression solution along the regularization path.
Return sum(xi * yi) / (sum(xi ** 2) + lam). An empty input returns 0.0. Larger lam shrinks the coefficient toward zero.
Hint
Ridge adds lam to the Gram diagonal, which for one feature is sum(xi ** 2).
Test cases
case 1
in: [[1,2,3],[2,4,6],0]
expected: 2
case 2
in: [[1,2,3],[2,4,6],5]
expected: 1.4736842105263157
case 3
in: [[1,1],[1,-1],2]
expected: 0
case 4
in: [[],[],1]
expected: 0
Starter codePython
def ridge_path_value(X, y, lam):
# Your code here
pass4 test cases · run your code against them in the editor