spsanderson / tidyAML

Auto ML for the tidyverse
http://www.spsanderson.com/tidyAML/
Other
63 stars 7 forks source link

Update `fast_regression()` and `fast_classification()` to drop NULL pred_wflw from output #222

Closed spsanderson closed 7 months ago

spsanderson commented 7 months ago

Currently fast_classification() and fast_regression() do not suppress models with NULL for the pred_wflw column and should.

Example:

library(recipes)
library(tidyAML)
library(tidymodels)
library(tidyverse)
library(multilevelmod)
tidymodels_prefer()

rec_obj <- recipe(mpg ~ ., data = mtcars)
frt_tbl <- fast_regression(
  mtcars, 
  rec_obj,
  .parsnip_eng = "all",
  .parsnip_fns = "all"
)

> extract_wflw_pred(frt_tbl, 2)
# A tibble: 0 × 2
# ℹ 2 variables: .model_type <chr>, pred_wflw <???>
> extract_regression_residuals(frt_tbl[2,])
Error in `map2()`:
ℹ In index: 1.
Caused by error in `UseMethod()`:
! no applicable method for 'select' applied to an object of class "NULL"
Run `rlang::last_trace()` to see where the error occurred.

Fix:

mod_pred_tbl <- mod_pred_tbl[!sapply(mod_pred_tbl$fitted_wflw, function(x) length(x) == 0), ]
mod_pred_tbl <- mod_pred_tbl[!sapply(mod_pred_tbl$pred_wflw, function(x) length(x) == 0), ]