-
Notifications
You must be signed in to change notification settings - Fork 90
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
Supporting quantile regression with XGBoost #1143
Comments
I also am extremely interested in quantile regression being added to parsnip, but that feature is (AFAICT) not available yet in the xgboost R package, and probably will be some time coming still. They are rewriting the entire R interface to the underlying xgboost library and won't enable quantile regression until that's done. Skimming the linked issue, I think there is still a lot of work to do. |
While I have used "reg::quantileerror", for But one thing to note is that library(tidymodels)
library(bonsai)
library(lightgbm)
tidymodels_prefer()
data(Chicago)
n <- nrow(Chicago)
Chicago <- Chicago %>% select(ridership, Clark_Lake, Quincy_Wells)
Chicago_train <- Chicago[1:(n - 7), ]
Chicago_test <- Chicago[(n - 6):n, ]
# spec ---
bt_reg_spec <-
boost_tree(trees = 15) %>%
set_mode("regression") %>%
# passing quantilereg via ellipsis to xgboost engine:
# need at least dev verson 2.0.0 for "reg:quantileerror"
# set_engine("xgboost", objective = "reg:quantileerror", quantile_alpha = .8)
# available in lightgbm CRAN version:
set_engine("lightgbm", objective = "quantile", alpha = .8)
bt_reg_spec
#> Boosted Tree Model Specification (regression)
#>
#> Main Arguments:
#> trees = 15
#>
#> Engine-Specific Arguments:
#> objective = quantile
#> alpha = 0.8
#>
#> Computational engine: lightgbm
# fit
set.seed(1)
bt_reg_fit <- bt_reg_spec %>% fit(ridership ~ ., data = Chicago_train)
bt_reg_fit
#> parsnip model object
#>
#> LightGBM Model (15 trees)
#> Objective: quantile
#> Fitted to dataset with 2 columns
predict(bt_reg_fit, Chicago_test)
#> # A tibble: 7 × 1
#> .pred
#> <dbl>
#> 1 21.0
#> 2 21.5
#> 3 21.5
#> 4 21.4
#> 5 19.9
#> 6 10.8
#> 7 9.62 Created on 2025-03-25 with reprex v2.1.1 From what I can tell, a single model can only solve for a single quantile at a time with both xgb and lgbm engine backends. I think this is where the @simonpcouch / @topepo - at first this seemed like an easy item to register to
I would also second a swappable engine on |
Feature
In situations when one wants to use R to do a quantile regression, the options available are fairly limited - the
quantreg
package andquantregForests
are two.On the other hand, since version 2.0.0, XGBoost also provides a quantile regression option, available in the R package as well.
boost_tree
so that quantile regression with xgboost is available out of the boxprobably::int_conformal_quantile
it might also be useful to give an option to use the xgboost quantile regression or the quantreg rq function instead of regression forests.The text was updated successfully, but these errors were encountered: