question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistency between coef_ and coef_path_ in LassoLars

See original GitHub issue

Describe the issue linked to the documentation

Hello, the coef_ attribute from LassoLars returns the array of coefficients for the value of alpha given in parameter (1 by default). The coef_path_attribute is described in the doc as follow : “The varying values of the coefficients along the path”. However, the last column of the coef_path_ doesn’t match the values of the coef_ attribute, whereas the alpha value for this column is corresponding to the one given in parameter, hence the values of coefficients should be the same.

For example, if I run :

from sklearn.linear_model import LassoLars
from sklearn.datasets import make_regression

X, y = make_regression(n_samples=50,
                       n_features=10,
                       n_informative=3)

lasso = LassoLars().fit(X, y)

coef_ will look like :

array([ 0.        , 39.89632517, 77.75976515, 88.68204422,  0.        ,
        0.        ,  0.        ,  0.        ,  0.        ,  0.        ])

and coef_path_ :

array([[  0.        ,   0.        ,   0.        ,   0.        ],
       [  0.        ,   0.        ,   0.        , 289.86068748],
       [  0.        ,   0.        , 122.80186215, 573.97268871],
       [  0.        , 123.33792921, 246.13979136, 584.906583  ],
       [  0.        ,   0.        ,   0.        ,   0.        ],
       [  0.        ,   0.        ,   0.        ,   0.        ],
       [  0.        ,   0.        ,   0.        ,   0.        ],
       [  0.        ,   0.        ,   0.        ,   0.        ],
       [  0.        ,   0.        ,   0.        ,   0.        ],
       [  0.        ,   0.        ,   0.        ,   0.        ]])

Suggest a potential alternative/fix

Either normalize the 2 attributes in the same way, or give additional information about the coef_path_ values in the doc.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
FloWPscommented, Jun 30, 2020

Thank you for your answer !

And what do you think of my suggestion to normalize the coef_path_ attribute as well ? I don’t really see the point keeping the coefficients from coef_path_ at a different scale than that at which it has been defined for the coef__ attribute.

1reaction
thomasjpfancommented, Jun 26, 2020

The coef_ is normalized to the scale of X:

from sklearn.linear_model import LassoLars
from sklearn.datasets import make_regression

X, y = make_regression(n_samples=50,
                       n_features=10,
                       n_informative=3,
                       random_state=42)

lasso = LassoLars(random_state=42).fit(X, y)

X_scale = np.linalg.norm(X - np.average(X, axis=0), axis=0, ord=2) 

lasso.coef_ * X_scale gives:

>>> lasso.coef_ * X_scale
array([351.66080929,   0.        ,   0.        ,   0.        ,
         0.        , 235.00745073,   0.        ,   0.        ,
         0.        , 375.50644259])

which is the last entry of lasso.coef_path_. This happens when fit_intercept=True. Maybe the documentation could be more clear with this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intuitive explanation for inconsistency between regression and ...
An independent variable in a linear regression I am working on has positive coefficient but this variable has a negative correlation with ...
Read more >
coefpath — Plot path of coefficients after lasso - Stata
coefpath graphs the coefficient paths after any lasso fit using selection(cv), selec- tion(adaptive), selection(bic), or selection(none).
Read more >
sklearn.linear_model.LassoLars
Only coefficients up to the smallest alpha value ( alphas_[alphas_ > 0.].min() when fit_path=True) reached by the stepwise Lars-Lasso algorithm are ...
Read more >
Use variable labels in the coefpath graph after lasso estimation
I am trying to plot the coefficient paths after running a lass command. I am surprised that I cannot seem to find an...
Read more >
The Lasso Problem and Uniqueness - Statistics & Data Science
the lasso problem will have many coefficients set exactly to zero, due to the ... Do lasso estimates suffer from the same sign...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found