Skip to content
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

model.fit fails due to reshaping error in predict_proba() #25

Closed
Visdoom opened this issue Aug 23, 2017 · 0 comments · Fixed by #51
Closed

model.fit fails due to reshaping error in predict_proba() #25

Visdoom opened this issue Aug 23, 2017 · 0 comments · Fixed by #51

Comments

@Visdoom
Copy link

Visdoom commented Aug 23, 2017

Hey there,
I've been trying to fit an Elastic Net with your toolbox and ran into an error:

In the logistic.py class in the predict_proba() function you have the following code:

       z = self.decision_function(X, lamb)
        expit(z, z)
       # z = np.atleast_2d(z)

        # reshape z to (n_samples, n_classes, n_lambda)
        n_lambda = len(np.atleast_1d(lamb))
        z = z.reshape(z.shape[0], -1, n_lambda)

However, when the passed X is only one-dimensional and let's say n_lambda = 86, then z.shape() will return the number of lambdas ( as in (86,) , not (1,86)). Which leads the reshape to fail since it tries to shape a 1x86 array into an 86xKx86 array.

As you can see, I added the
z = np.atleast_2d(z)
line which takes care of the reshaping problem. However, then I this kind of error:

/usr/local/lib/python3.4/dist-packages/glmnet/logistic.py in predict(self, X, lamb)
    478         indices = scores.argmax(axis=1)
    479 
--> 480         return self.classes_[indices]
    481 
    482     def score(self, X, y, lamb=None):

IndexError: index 85 is out of bounds for axis 1 with size 2

since then the output is apparently not in the expected shape anymore.
I believe, this error could be fixed with a simple axis=0 in line 478, but I do not have the overview so I thought it's better to report back to you.

Best,
Sophie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant