-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[python-package][R-package] allow using feature names when retrieving number of bins #5116
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22b49d9
allow using feature names when retrieving number of bins
jmoralez b52c2b8
unname vector
jmoralez 87b57ca
use default feature names when not defined
jmoralez fa00975
lint
jmoralez fe6c9b4
apply suggestions
jmoralez a4d5237
Merge branch 'master' into feature-bin-by-name
jmoralez bc5931f
remove extra comma
jmoralez 6c59853
merge master
jmoralez 912a649
add test with categorical feature
jmoralez 302a6a1
make feature names sync more transparent
jmoralez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand the discussion in https://github.com/microsoft/LightGBM/pull/5116/files#r843276288 that led to this change, but I don't understand why adding this call here is necessary for the R package and I don't think it's achieving what you want (avoiding a call to the C++ side for performance reasons in
Dataset$get_feature_num_bin()
).The use of
colnames(self)
down in this PR's proposed change toDataset$get_feature_num_bin()
will still make a call to the C++ side.colnames()
called on aDataset
callsdimnames.lgb.Dataset()
, which callsself$get_colnames()
, which gets feature names from the C++ side for a constructed Dataset.LightGBM/R-package/R/lgb.Dataset.R
Line 983 in b462d0a
If you want to avoid that call to the C++ side, I think the code in
Dataset$get_feature_num_bin()
could just referenceprivate$colnames
directly.Consider the following example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. You're right, the call in the
Dataset$get_feature_num_bin()
should useprivate$colnames
. The line here however tries to mimic the one on the python side when after constructing the dataset callsself.feature_name = self.get_feature_name()
to make sure that the feature names on the python side are the same as the ones on the C++ side. This is for the case when nocolnames
are provided in the constructor but the default names are assigned on the C++ side and we want to retrieve the feature bins by the default names, because in that caseprivate$colnames
isNULL
until we callself$get_colnames()
once.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see. I still think it is not obvious, when looking at this line, that that's what is happening. It just looks like a call that got left behind, whose result isn't assigned.
Since you already know with certainty that at this point in
Dataset$construct()
thatDataset
has been constructed, I think it would be clearer to directly setprivate$colnames
like this:Instead of relying on the fact that
self$get_colnames()
happens to do that while it's also getting the features from the C++ side.Looking at this again, I also recommend reformatting this comment to the following:
So that it's a bit clearer when this can happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 302a6a1