Closed jrosell closed 1 week ago
Not sure if this is related, but I'm having trouble processing an {orbital} object using a trained XGBoost workflow()
that was trimmed down with {butcher}. Thanks Emil & team.
i see you! I'll see if I can take a look at this thursday or friday
this is indeed a bug. We will see what we can do!
below is a smaller reprex
library(tidymodels)
library(bundle)
library(orbital)
mod <- boost_tree(trees = 5, mtry = 3) %>%
set_mode("regression") %>%
set_engine("xgboost") %>%
fit(mpg ~ ., data = mtcars[1:25,])
orbital(mod)
#>
#> ── orbital Object ──────────────────────────────────────────────────────────────
#> • .pred = 0 + case_when((cyl < 7 | is.na(cyl)) ~ 6.432858, cyl >= 7 ~ 4.0 ...
#> ────────────────────────────────────────────────────────────────────────────────
#> 1 equations in total.
mod_bundle <- bundle(mod)
mod_new <- unbundle(mod_bundle)
orbital(mod_new)
#> Error in data.frame(Feature = as.character(0:(length(feature_names) - : arguments imply differing number of rows: 2, 0
# Because
mod$fit$nfeatures
#> [1] 10
mod$fit$feature_names
#> [1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
mod_new$fit$nfeatures
#> NULL
mod_new$fit$feature_names
#> NULL
@JavOrraca
butchering does not appear to xgboost, so there is another issue at hand
library(tidymodels)
library(butcher)
library(orbital)
mod <- boost_tree(trees = 5, mtry = 3) %>%
set_mode("regression") %>%
set_engine("xgboost") %>%
fit(mpg ~ ., data = mtcars[1:25,])
orbital(mod)
#>
#> ── orbital Object ──────────────────────────────────────────────────────────────
#> • .pred = 0 + case_when((disp < 266.9 | is.na(disp)) ~ 6.432.58, disp >= ...
#> ────────────────────────────────────────────────────────────────────────────────
#> 1 equations in total.
mod_butcher <- butcher(mod)
orbital(mod_butcher)
#>
#> ── orbital Object ──────────────────────────────────────────────────────────────
#> • .pred = 0 + case_when((disp < 266.9 | is.na(disp)) ~ 6.432.58, disp >= ...
#> ────────────────────────────────────────────────────────────────────────────────
#> 1 equations in total.
mod$fit$nfeatures
#> [1] 10
mod$fit$feature_names
#> [1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
mod_butcher$fit$nfeatures
#> [1] 10
mod_butcher$fit$feature_names
#> [1] "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" "carb"
Created on 2024-11-07 with reprex v2.1.0
Thanks!
Just to confirm that is fixed with the new version of {bundle}
library(tidymodels)
library(bundle)
library(orbital)
mod <- boost_tree(trees = 5, mtry = 3) %>%
set_mode("regression") %>%
set_engine("xgboost") %>%
fit(mpg ~ ., data = mtcars[1:25,])
orbital(mod)
#>
#> ── orbital Object ──────────────────────────────────────────────────────────────
#> • .pred = 0 + case_when((hp < 136.5 | is.na(hp)) ~ 6.432858, hp >= 136.5 ...
#> ────────────────────────────────────────────────────────────────────────────────
#> 1 equations in total.
mod_bundle <- bundle(mod)
mod_new <- unbundle(mod_bundle)
orbital(mod_new)
#>
#> ── orbital Object ──────────────────────────────────────────────────────────────
#> • .pred = 0 + case_when((hp < 136.5 | is.na(hp)) ~ 6.432858, hp >= 136.5 ...
#> ────────────────────────────────────────────────────────────────────────────────
#> 1 equations in total.
I'm having trouble when using {xgboost} with the {bundle} package in {orbital}. The strange thing is that other models work with {bundle} but not {xgboost}. TBH, I'm not sure if this bug report should be here at {orbital} or {tidypredict} or {bundle}.
Here an example: