-
Notifications
You must be signed in to change notification settings - Fork 214
DOC: sometimes the Lasso solution is the same as sklearn, sometimes not #186
Comments
setting |
it's like the random option in sklearn I suspect
… Message ID: ***@***.***
com>
|
Thanks for the repro @mathurinm! The
|
I also thought that there was an issue when the two of them were import numpy as np
from numpy.linalg import norm
from lightning.regression import CDRegressor
from sklearn.linear_model import Lasso
np.random.seed(0)
X = np.random.randn(200, 500)
beta = np.ones(X.shape[1])
beta[20:] = 0
y = X @ beta + 0.3 * np.random.randn(X.shape[0])
alpha = norm(X.T @ y, ord=np.inf) / 100
def p_obj(X, y, alpha, w):
return norm(y - X @ w) ** 2 / 2 + alpha * norm(w, ord=1)
for shrinking in (True, False):
seed = 0
print('-' * 80)
print(f"With shrinking={shrinking} and permute=False")
clf = CDRegressor(C=0.5, alpha=alpha, penalty='l1',
tol=1-30, random_state=seed, permute=False,
shrinking=shrinking)
clf.fit(X, y)
las = Lasso(fit_intercept=False, alpha=alpha/len(y), max_iter=100_000,
tol=1e-10).fit(X, y)
print(f'distance between coeffs: {norm(clf.coef_[0] - las.coef_)}')
light_o = p_obj(X, y, alpha, clf.coef_[0])
sklea_o = p_obj(X, y, alpha, las.coef_)
print(f"lightning obj - sklearn_obj : {light_o - sklea_o:.7f}") |
Thanks a lot for the investigation @mathurinm! So it seems that |
Hi @mblondel @fabianp
I think this will be short to answer, why is the solution sometimes equal to that of sklearn, and sometimes not ?
This should be quick to reproduce, look at 1st and 3rd result over 5 seeds:
ping @QB3 @agramfort
The text was updated successfully, but these errors were encountered: