Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lars.coef_ broken when fit_path=True #1615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shoyer opened this issue Jan 23, 2013 · 10 comments · Fixed by #8160
Closed

Lars.coef_ broken when fit_path=True #1615

shoyer opened this issue Jan 23, 2013 · 10 comments · Fixed by #8160
Labels

Comments

@shoyer
Copy link
Contributor

shoyer commented Jan 23, 2013

I am using LassoLars to solve a multi-dimensional sparse coding problem. After upgrading from 0.12.1 to 0.13, I have encountered a bug where the coef_ attribute of LassoLars is a list, not a numpy array. This breaks the decision_function method, since it takes the transpose of coef_:

/export/disk0/wb/python2.6/lib/python2.6/site-packages/sklearn/linear_model/base.pyc in decision_function(self, X)
138 """
139 X = safe_asarray(X)
--> 140 return safe_sparse_dot(X, self.coef_.T) + self.intercept_
141
142 def predict(self, X):

AttributeError: 'list' object has no attribute 'T'

This seems to be due to this change that made it into the 0.13 release by @GaelVaroquaux:
e18465d

@amueller
Copy link
Member

Thanks for the report. I noticed the change in the API when doing the release. I didn't notice it broke the decision function. We seem to be missing some tests there.
We'll try to fix this asap.

@amueller
Copy link
Member

@GaelVaroquaux and maybe @vene could you maybe have a look on how to best resolve that?

@amueller
Copy link
Member

hm maybe we should just change the decision_function implementation...

@amueller
Copy link
Member

you could also just use predict instead of decision_function, right?
I really don't see why we have a decision_function on regressors....

@amueller
Copy link
Member

I am confused now... I can not reproduce that in master. Was that changed back again since the release?

@agramfort
Copy link
Member

it works for me too. Can you give a more detailed snippet to reproduce the
problem?

thanks

@shoyer
Copy link
Contributor Author

shoyer commented Jan 29, 2013

OK, let me see if I can isolate an appropriate example

@shoyer
Copy link
Contributor Author

shoyer commented Feb 14, 2013

I put off checking this, and now I actually can't seem to reproduce it in any of my code. Looks like it might have been my mistake -- oops!

@shoyer shoyer closed this as completed Feb 14, 2013
@amueller
Copy link
Member

No problem. Thanks for checking :)

@perimosocordiae
Copy link
Contributor

Sorry to resurrect an old issue, but I think this bug is still lurking. Here's a minimal repro on current master:

import numpy as np
from sklearn.linear_model import LassoLars

X = np.random.random((50, 3))
y = np.random.random((50, 2))

foo = LassoLars(fit_intercept=False)
foo.fit(X, y)
foo.predict(X)

Running it results in the same problem with trying to transpose a list:

Traceback (most recent call last):
  File "demo_bug.py", line 9, in <module>
    foo.predict(X)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 252, in predict
    return self._decision_function(X)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/base.py", line 236, in _decision_function
    return safe_sparse_dot(X, self.coef_.T,
AttributeError: 'list' object has no attribute 'T'

Some testing shows that the bug is only triggered with a 2D y and fit_intercept=False. Changing either of those conditions makes everything work as expected.

perimosocordiae added a commit to perimosocordiae/scikit-learn that referenced this issue Jan 5, 2017
jnothman pushed a commit that referenced this issue Jan 18, 2017
sergeyf pushed a commit to sergeyf/scikit-learn that referenced this issue Feb 28, 2017
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this issue Jun 14, 2017
NelleV pushed a commit to NelleV/scikit-learn that referenced this issue Aug 11, 2017
paulha pushed a commit to paulha/scikit-learn that referenced this issue Aug 19, 2017
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this issue Nov 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants