tidymodels / tailor

Iterative Steps for Postprocessing Model Predictions
https://tailor.tidymodels.org
Other
2 stars 0 forks source link

check tidyselect output before subsetting #21

Closed simonpcouch closed 4 months ago

simonpcouch commented 4 months ago

The first error message, when supplying a plain string, is helpful, but the latter two are a bit gnarly:

library(modeldata)
library(tailor)

tailor_fit <- tailor() %>%
  adjust_probability_threshold(.5) %>%
  fit(
    two_class_example,
    outcome = "truth",
    estimate = "predicted",
    probabilities = tidyselect::contains("Class")
  )

tailor_fit <- tailor() %>%
  adjust_probability_threshold(.5) %>%
  fit(
    two_class_example,
    outcome = "truth_WRONG",
    estimate = "predicted",
    probabilities = tidyselect::contains("Class")
  )
#> Error in `fit()`:
#> ! Can't select columns that don't exist.
#> ✖ Column `truth_WRONG` doesn't exist.

tailor_fit <- tailor() %>%
  adjust_probability_threshold(.5) %>%
  fit(
    two_class_example,
    outcome = contains("truth_WRONG"),
    estimate = "predicted",
    probabilities = tidyselect::contains("Class")
  )
#> Error in `.data[[columns$outcome]]`:
#> ! Can't extract column with `columns$outcome`.
#> ✖ Subscript `columns$outcome` must be size 1, not 0.

tailor_fit <- tailor() %>%
  adjust_probability_threshold(.5) %>%
  fit(
    two_class_example,
    outcome = contains("truth"),
    estimate = "predicted",
    probabilities = tidyselect::contains("Class_WRONG")
  )
#> Error in `new_data[[prob_nm]]`:
#> ! Can't extract column with `prob_nm`.
#> ✖ Subscript `prob_nm` must be a location, not a character `NA`.

Created on 2024-06-04 with reprex v2.1.0

simonpcouch commented 4 months ago

eval_select(allow_empty = TRUE) isn't quite what we want, as the error message doesn't give enough information:

> tailor_fit <- tailor() %>%
+   adjust_probability_threshold(.5) %>%
+   fit(
+     two_class_example,
+     outcome = contains("truth_WRONG"),
+     estimate = "predicted",
+     probabilities = tidyselect::contains("Class")
+   )
Error in `fit()`:
! Must select at least one item.