Skip to content

Correctness issue in LassoLars for unluckily aligned values #2746

Closed

Description

@fcole

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.

Activity

  1. agramfort commented on Jan 13, 2014

    @agramfort
    Member

    hum... do you have some time to investigate the issue? stability of LARS
    can be a pain...

  2. fcole commented on Jan 14, 2014

    @fcole
    Author

    I can't look into it right now, but the workaround is enough for me at the moment. I'm also not that familiar with the LARS algorithm.

  3. fcole commented on Jan 21, 2014

    @fcole
    Author

    So after reading through the LARS paper (Efron, et al., 2003), it looks like adding jitter to the samples to avoid the many-regressors-at-a-time problem is actually an expected part of the algorithm (section 5, last paragraph, page 32). Given that, it seems like the LassoLars call in sklearn should probably add some small amount of jitter automatically. I'm not sure how to determine how much should be added, though.

  4. modified the milestone: 0.19 on Sep 29, 2016
  5. modified the milestones: 0.20, 0.19 on Jun 14, 2017
  6. modified the milestones: 0.20, 0.21 on Jun 13, 2018
  7. added
    Easy
    on Apr 10, 2019
  8. jnothman commented on Apr 10, 2019

    @jnothman
    Member

    We can add a parameter where the user can specify how much jitter to add to y. In the post above, the jitter is uniformly distributed, but I assume gaussian jitter would work too, in which case the user could specify its variance?

  9. modified the milestones: 0.21, 0.22 on Apr 10, 2019
  10. fcole commented on Apr 10, 2019

    @fcole
    Author

    Wow, thanks for taking a look at this.

    Yes, I'd figure some kind of noise parameter with a sensible default (maybe 10e-5 or something for single-precision floats) should work. I guess it doesn't matter much, but uniform noise might be preferable to gaussian since the parameter could be a bound on the magnitude of the noise.

  11. angelaambroz commented on Oct 10, 2019

    @angelaambroz
    Contributor

    ✋ I'd be happy to work on this as my first sklearn PR. To summarize my understanding:

    • We need to add a noise kwarg to the LassoLars.fit() function.
    • Two options on the noise's distribution: uniform and bounded by the param; or Gaussian with the param being its variance. I can implement uniform to start with and make the PR, we can discuss further there.
    • Probably a test of some kind... I can take a look at how other .fit functions get tested.

    To get set up, I'll make sure to read through the contributing docs, get my environment set up, and read Efron et al. 2003. 😅

  12. jnothman commented on Oct 10, 2019

    @jnothman
    Member
  13. modified the milestones: 0.22, 0.23 on Oct 31, 2019
  14. thomasjpfan commented on Apr 20, 2020

    @thomasjpfan
    Member

    Resolved in #15179

  15. fcole commented on Apr 20, 2020

    @fcole
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugEasy

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions