Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
lasso init in sklearn
import numpy as np
from sklearn.datasets.samples_generator import make_regression
from sklearn.linear_model import Lasso
X, y = make_regression(n_samples=200, n_features=5000, random_state=0)
dense_lasso = Lasso(alpha=1, fit_intercept=False, max_iter=1000), y)
print('iterations needed: ', dense_lasso.n_iter_)
init_lasso = Lasso(alpha=1, fit_intercept=False, max_iter=1000, warm_start=True)
init_lasso.coef_ = dense_lasso.coef_ + np.random.uniform(size=dense_lasso.coef_.shape[0]), y)
print('iterations needed using init: ', init_lasso.n_iter_)
init_lasso_no_noise = Lasso(alpha=1, fit_intercept=False, max_iter=1000, warm_start=True)
init_lasso_no_noise.coef_ = dense_lasso.coef_, y)
print('iterations needed using init: ', init_lasso_no_noise.n_iter_)
# Output:
# iterations needed: 61
# iterations needed using init: 11
# iterations needed using init: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment