Repository navigation
[docs] [python-package] Update pandas categorical feature encoding details - #7250
Conversation
Clarified encoding requirements for categorical features and added a note about category handling in LightGBM. Related lightgbm-org#2761 (comment)
jameslamb
left a comment
There was a problem hiding this comment.
Thanks for your interest in LightGBM. I agree that this is a gap in the documentation, and appreciate you taking the time to open a PR! I've left some suggestions.
The application of training categories to prediction data is done here: https://github.com/henry0312/LightGBM/blob/ad487fee57945f45041ff21038dfeaaee4e10e52/python-package/lightgbm/basic.py#L684
How did you end up using a many-years-out-of-date old maintainer's fork for this link? I'm genuinely curious, I was really surprised to see that link.
In this repo, here in 2026, I think the relevant code snippet would be:
LightGBM/python-package/lightgbm/basic.py
Lines 852 to 854 in 9545905
Note that posting a link from within the same repo has the nice side effect of the code being rendered in the GitHub UI, so it's visible without clicking through.
I tried to trace back my steps but honestly I have no idea π Good to know about the rendering! I've updated this branch with your comments, curious to see what you think. |
jameslamb
left a comment
There was a problem hiding this comment.
Changes look good, thanks very much!
Don't worry about the failing CI jobs, we have some ongoing issues right now (the global Ubuntu packages outage and #7248). I'll get this PR updated and merged once those are resolved, nothing else you need to do for this one.
|
Thanks @maxzw , and sorry it took so long to merge this! Will try to get your other PRs moving as soon as we land #7275 (just waiting on reviews there). Are there other areas not related to array processing you're interested in? I'd be happy to suggest some other places where LightGBM could use help. |
The current documentation states
However, this statement alone leaves out a very important nuance: if the category mapping observed using during prediction differs from the mapping observed during training, the mapping of the training data is applied to the prediction dataset. This is important information, because this means that categorical encodings are part of the learning process of LightGBM and no external data processing is required to prevent mixing up categorical codes (e.g. OrdinalEncoder).
Related to this discussion: #2761
The application of training categories to prediction data is done here:
LightGBM/python-package/lightgbm/basic.py
Lines 852 to 854 in 9545905