Premium problem134. Ridge Regression in Closed Form

Medium Locked

Given X (n, d), targets y (n,) and scalar lam >= 0, return the (d+1,) coefficient vector:

  • intercept first
  • it minimises ||Xw + b - y||^2 + lam * ||w||^2
  • the intercept must not be penalised

Input

X =
[[1.]
 [2.]
 [3.]]
y = [2. 4. 6.]
lam = 0.0

Output

[0. 2.]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)