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

Using/Adding feature_weights in R #7657

Closed
hetong007 opened this issue Feb 15, 2022 · 7 comments · Fixed by #7660
Closed

Using/Adding feature_weights in R #7657

hetong007 opened this issue Feb 15, 2022 · 7 comments · Fixed by #7660

Comments

@hetong007
Copy link
Member

I received a feature request via email from Prof. Tibshirani:

I am an avid user of the  superb  XGBoost pkg in R.

A question: the python version has a feature_weights argument that I find very useful. This option does not appear to be available in R. Would it be possible to
add this to the R pkg?

thanks!

sincerely

Rob Tibshirani

My questions are:

  • If the R package indeed has this feature, how would one use it?
  • If it doesn't have it yet, could we have it in R?

Thanks!

@trivialfis
Copy link
Member

trivialfis commented Feb 15, 2022

It's just a meta info like labels and weights. I can help add that to R if needed.

@tibshirani
Copy link

That would be great!

@tibshirani
Copy link

I would just like to pass a vector of non-negative weights, of length the number of columns in the feature matrix.

@trivialfis trivialfis added this to Need prioritize in 2.0 Roadmap via automation Feb 15, 2022
@tibshirani
Copy link

I have a new research project for which the feature_weights in xgboost are essential. Thank you for adding this to your
prioritize list. Is this something that is likely to happen relatiively soon? o/w is it simple enough that I could ask a grad student who knows python (not me) to create a local version with feature_weights?

@hetong007
Copy link
Member Author

I think it is relatively easy to enable it by someone familiar with R. Basically one can add the below condition branch in this function: https://github.com/dmlc/xgboost/blob/master/R-package/R/xgb.DMatrix.R#L255

...
if (name == "feature_weights") {
    if (sum(info) != ncol(object))
        stop("The number of feature weights must equal to the number of columns in the input data")
    .Call(XGDMatrixSetInfo_R, object, name, as.numeric(info))
    return(TRUE)
}
...

@trivialfis Please correct me if this is not true.

@trivialfis
Copy link
Member

Looks right, I will work on it tonight.

@tibshirani
Copy link

Wonderful! Thanks so much

rob

@trivialfis trivialfis moved this from Need prioritize to 1.6 In Progress in 2.0 Roadmap Feb 16, 2022
@trivialfis trivialfis moved this from 1.6 In Progress to 1.6 Done in 2.0 Roadmap Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants