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

NGBClassifier predict error #52

Closed
juanramonua opened this issue Dec 16, 2019 · 2 comments
Closed

NGBClassifier predict error #52

juanramonua opened this issue Dec 16, 2019 · 2 comments
Assignees

Comments

@juanramonua
Copy link

Running your code from https://github.com/stanfordmlgroup/ngboost/blob/master/examples/classification.py
I received the following error when I try

ngb.predict(X_test)

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
----> 1 ngb.predict(X_test)

/usr/local/lib/python3.6/dist-packages/ngboost/ngboost.py in predict(self, X)
133 def predict(self, X):
134 dist = self.pred_dist(X)
--> 135 return list(dist.loc.flatten())
136
137 def score(self, X, Y):

AttributeError: 'NoneType' object has no attribute 'flatten'
----------------------------------------------------------------`

ngb.pred_dist(X_test) works properly but the above error is also obtained when using the sklearn function with cross validation, "cross_validate()".

Regards,

@alejandroschuler
Copy link
Collaborator

Good catch... I looked into it and this is happening because the way predict is implemented right now is a bit silly and only works for distributions that have a loc parameter.

The way to fix this, imo, is to define a predict method for all distributions that returns the conditional mean (i.e. the loc parameter for those we've implemented) for continuous distributions and the conditional mode (i.e. the most likely class) for discrete distributions. We can probably even use the underlying scipy distributions for this. I'll do that sometime soon.

In the meantime, you can easily get the predicted class by doing ngb.pred_dist(X_test).prob > 0.5.

@alejandroschuler alejandroschuler self-assigned this Dec 30, 2019
@alejandroschuler
Copy link
Collaborator

Ok, I've fixed this issue with c054851. Please do play around with it and let me know if this now works for you and/or if you want other features.

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

No branches or pull requests

2 participants