Repository navigation
[python-package] plot_importance(): raise clearer exception when model has 0 splits - #7160
Merged
Merged
Conversation
juanf-0gravity
requested review from
StrikerRUS,
borchero,
guolinke,
jameslamb,
jmoralez and
shiyu1994
as code owners
February 21, 2026 16:30
Contributor
Author
|
@microsoft-github-policy-service agree |
jameslamb
requested changes
Feb 28, 2026
jameslamb
left a comment
Member
There was a problem hiding this comment.
Just one small suggestion, otherwise this looks great to me.
Thanks so much for taking the time to contribute!
Comment on lines
+133
to
+136
| raise ValueError( | ||
| "No non-zero feature importances found. The model may have no splits. " | ||
| "Use ignore_zero=False to show all features." | ||
| ) |
Member
There was a problem hiding this comment.
Thanks for using "may" here, I think that's right.
There are 2 ways I can think of that you can end up in this situation:
- using
importance_type="split"and there are 0 splits - using
importance_type="gain"and there are splits, but the gain is so small that it's== 0due to numerical precision issues
This error message is great.
Member
jameslamb
approved these changes
Mar 1, 2026
jameslamb
left a comment
Member
There was a problem hiding this comment.
This is looking good, thanks so much for taking the time to contribute!
I'll merge this if CI passes.
Contributor
Author
|
Thanks for the review, I'll keep that in mind for future contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6865
When a model has 0 splits (e.g. too few samples for LightGBM to find useful features), all feature importances are zero. With
ignore_zero=True(the default), the filtering removes everything andzip(*tuples)crashes withValueError: not enough values to unpack.Added a guard that raises a clear
ValueErrorwith a message pointing users toignore_zero=False. Also added a test that verifies both the error case and theignore_zero=Falsefallback.@jameslamb tagging you as suggested.