Skip to content

Quantile regression integration#1127

Open
topepo wants to merge 8 commits intomainfrom
quantile-reg-integration
Open

Quantile regression integration#1127
topepo wants to merge 8 commits intomainfrom
quantile-reg-integration

Conversation

@topepo
Copy link
Member

@topepo topepo commented Jan 30, 2026

Closes #1125

Enables quantile regression models to be resampled and tuned.

Notes:

  • The prediction summarization code can use some optimization but works fairly well.
  • Takes parsnip and yardstick remotes. (EDIT)

An example:

library(tidymodels)
mirai::daemons(10)

set.seed(1)
sim_dat <- sim_regression(2000)
sim_rs <- vfold_cv(sim_dat)

bst_spec <-
  boost_tree(min_n = tune(), trees = 100, learn_rate = tune()) |>
  set_mode("quantile regression", quantile_levels = (0:10) / 10)

set.seed(2)
bst_res <-
  bst_spec |>
  tune_grid(
    outcome ~ .,
    resamples = sim_rs,
    control = control_grid(save_pred = TRUE, save_workflow = TRUE),
    grid = 25
  )

show_best(bst_res, metric = "weighted_interval_score")
#> # A tibble: 5 × 8
#>   min_n learn_rate .metric                .estimator  mean     n std_err .config
#>   <int>      <dbl> <chr>                  <chr>      <dbl> <int>   <dbl> <chr>  
#> 1    33     0.249  weighted_interval_sco… standard    4.73    10   0.113 pre0_m…
#> 2    19     0.316  weighted_interval_sco… standard    4.91    10   0.114 pre0_m…
#> 3    25     0.154  weighted_interval_sco… standard    5.00    10   0.132 pre0_m…
#> 4    11     0.196  weighted_interval_sco… standard    5.16    10   0.129 pre0_m…
#> 5    40     0.0953 weighted_interval_sco… standard    5.36    10   0.136 pre0_m…
bst_best <- select_best(bst_res, metric = "weighted_interval_score")
bst_best
#> # A tibble: 1 × 3
#>   min_n learn_rate .config         
#>   <int>      <dbl> <chr>           
#> 1    33      0.249 pre0_mod21_post0
fit_best(bst_res, metric = "weighted_interval_score")
#> ══ Workflow [trained] ══════════════════════════════════════════════════════════
#> Preprocessor: Formula
#> Model: boost_tree()
#> 
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> outcome ~ .
#> 
#> ── Model ───────────────────────────────────────────────────────────────────────
#> ##### xgb.Booster
#> call:
#>   xgboost::xgb.train(params = list(eta = 0.248790236723884, max_depth = 6, 
#>     gamma = 0, colsample_bytree = 1, colsample_bynode = 1, min_child_weight = 33L, 
#>     subsample = 1, objective = "reg:quantileerror", nthread = 1, 
#>     quantile_alpha = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 
#>     0.8, 0.9, 1)), data = x$data, nrounds = 100, evals = x$watchlist, 
#>     verbose = 0)
#> # of features: 20 
#> # of rounds:  100 
#> callbacks:
#>    evaluation_log 
#> evaluation_log:
#>   iter training_quantile
#>  <num>             <num>
#>      1          4.456474
#>      2          4.068782
#>    ---               ---
#>     99          1.046341
#>    100          1.041209

bst_res |> 
  collect_metrics() |> 
  ggplot(aes(learn_rate, min_n, size = mean)) +
  geom_point() + 
  scale_x_log10() +
  coord_fixed(1/15)

int_pctl(bst_res, parameters = bst_best, alpha = 0.1, times = 1000)
#> # A tibble: 1 × 8
#>   min_n learn_rate .metric            .estimator .lower .estimate .upper .config
#>   <int>      <dbl> <chr>              <chr>       <dbl>     <dbl>  <dbl> <chr>  
#> 1    33      0.249 weighted_interval… bootstrap    4.56      4.72   4.91 pre0_m…

Created on 2026-01-30 with reprex v2.1.1

@topepo
Copy link
Member Author

topepo commented Jan 30, 2026

macOS error seems to be due to a CRAN issue with a package. I'll rerun periodically, but this is ready for review.

Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking very nice!

you also need to add a news bullet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable quantile regression models

2 participants