-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Correctness issue in LassoLars for unluckily aligned values #2746
Description
I think I've found a correctness bug in sklearn.linear_model.LassoLars. For me it appears only for systems with some exactly aligned (i.e., non-general position) values. It can be fixed by jiggling the RHS of the system with small random offsets. Here is test python code:
import numpy as np
import sklearn.linear_model as sklm
A = np.array([[0.0,0.0,0.0,-1.0,0.0], [0.0,-1.0,0.0,0.0,0.0]])
b = np.array([-2.5,-2.5])
lars = sklm.LassoLars(alpha=0.001, fit_intercept=False)
lars.fit(A,b)
w_nojiggle = lars.coef_
jiggle_b = b + np.random.rand(2) * 0.00001
lars.fit(A,jiggle_b)
w_jiggle = lars.coef_
print 'without jiggle: ', w_nojiggle, ', residual: ', np.dot(A,w_nojiggle) - b
print 'with jiggle: ', w_jiggle, ', residual: ', np.dot(A,w_jiggle) - b
For me with the current Anaconda distribution (sklearn.version == '0.14.1'), the output is:
without jiggle: [ 0. 4.998 0. 2.498 0. ] , residual: [ 2.00000000e-03 -2.49800000e+00]
with jiggle: [ 0. 2.49799528 0. 2.49799561 0. ] , residual: [ 0.00200439 0.00200472]
The jiggled version has the expected result, whereas the no jiggle version is wrong.