-
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
[R-package] Rename weight
-> weights
#4975
Conversation
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.
Thanks for the proposal and for fixing the documentation!
I checked the various packages you mentioned and can confirm that weights
(with an s
) is used across many of them. Thanks for listing those out!
this is not a breaking change since existing code using
weight
would still work under this PR
@StrikerRUS I noticed you changed the label on this PR to "breaking". I'm going to change it back to "feature". As @david-cortes is alluding to, R allows for partial matching of keyword argument names.
f <- function(weights){
print(weights + 5)
}
f(weight = 7)
# 12
@david-cortes will you please add a unit test confirming that weighted training with lightgbm::lightgbm()
works as expected using both keyword argument weight
and weights
? As a general rule, every user-facing change to this project should be accompanied by tests demonstrating their correctness and ensuring that we don't accidentally break that behavior with future.
I recall that previously, R CMD check
complained about the use of partial argument-matching in package code (#3629). If it complains about such a unit test, then I wouldn't support changing this keyword argument. But if it's possible to keep a test demonstrating that both weight
and weights
work, then I support this change to make lightgbm::lightgbm()
a bit more consistent with other statistical modeling packages in R.
Sorry, my bad!
Wow! Didn't know about that, interesting feature! |
Added tests. |
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.
excellent, thanks very much!
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
ref #4968
The
lightgbm()
function accept observation weights as a parameter namedweight
. In base R and in other popular R packages for decision trees (and for other model types too) the convention is to name this argumentweights
instead.Example decision tree packages naming it
weights
:ranger
(as "case.weights"),gbm
,rpart
,C5.0
,party
,evtree
, (and wrappers over them such ascaret
).The only popular decision tree library I could find naming them
weight
is xgboost. I'll also have to guess that the ratio ofweights
toweight
would be even higher among linear modeling packages.As such, this PR changes the name of the argument to be more in line with the rest of the R libraries which users are likely to be familiar with. Additionally, it changes the documentation which incorrectly describes this parameter as being the response value (which it isn't).
It should be noted that this is not a breaking change since existing code using
weight
would still work under this PR.