Skip to content

Instantly share code, notes, and snippets.

@fabianp
Created July 11, 2011 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianp/1076792 to your computer and use it in GitHub Desktop.
Save fabianp/1076792 to your computer and use it in GitHub Desktop.
Ridge regression
import numpy as np
from scipy import linalg
def ridge(A, b, alphas):
"""Return coefficients for regularized least squares
||A x - b|| + alpha ||x||
"""
U, s, V = linalg.svd(X, full_matrices=False)
d = np.dot(U.T, y) / (s + alphas[:, np.newaxis] / s)
return np.dot(d, V)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment