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

Only copy pandas categorical attribute if it exists #1764

Closed

Conversation

rostyboost
Copy link

In case:

  • a model was trained on numpy arrays (not pandas dataframe)
  • was serialized with model_to_string
  • was deserialized by instantiating a Booster with the model_str parameter (see here)
  • was queried with .predict on a numpy array again

Then the current master branch crashes with:

  File "/usr/local/lib/python2.7/site-packages/lightgbm/basic.py", line 2216, in _to_predictor
    predictor.pandas_categorical = self.pandas_categorical
AttributeError: 'Booster' object has no attribute 'pandas_categorical'

This PR fixes it.

@StrikerRUS
Copy link
Collaborator

@rostyboost Thanks a lot for your help!

However, the problem seems to be more fundamental: model_to_string and dump_model methods ignore pandas_categorical field at all.

Let me dig deeper...
I remember, there was the same problem with Dataset class more than year ago (#218), which @wxchan solved.

@rostyboost It will be very helpful if you can post a reproducible example. Thanks.

@StrikerRUS
Copy link
Collaborator

@rostyboost Please try #1766, it should solve your problem.

@StrikerRUS StrikerRUS closed this Oct 21, 2018
@rostyboost
Copy link
Author

#1766 works. thanks

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants