Created
June 25, 2014 06:30
-
-
Save MechCoder/edda4ff2f04b48fd15ee to your computer and use it in GitHub Desktop.
Beching to measure the effect of random descent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy import signal | |
rng = np.random.RandomState(42) | |
n_samples, n_features, k = 500, 1000, 10 | |
h = signal.gaussian(50, 15) | |
X = signal.convolve2d(np.eye(n_features), h[:, np.newaxis], 'same') # convolutional design | |
X = X[::n_features // n_samples] | |
coef0 = rng.randn(n_features) | |
coef0[np.abs(coef0) < np.sort(np.abs(coef0))[-k]] = 0 | |
y = np.dot(X, coef0) | |
alpha = 0.001 | |
from sklearn.linear_model import Lasso | |
clf = Lasso(alpha=alpha, random_state=0) | |
clf.fit(X, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment