Skip to contents

`step_select_roc` creates a *specification* of a recipe step that will filter predictors using their relationship with the outcome as measured using a Receiver Operating Characteristic curve.

Usage

step_select_roc(
  recipe,
  ...,
  outcome,
  role = "predictor",
  trained = FALSE,
  threshold = NA,
  top_p = NA,
  cutoff = NA,
  exclude = NULL,
  skip = FALSE,
  id = recipes::rand_id("select_roc")
)

# S3 method for step_select_roc
tidy(x, ...)

Arguments

recipe

A recipe object. The step will be added to the sequence of operations for this recipe.

...

One or more selector functions to choose which predictors are affected by the step. See [selections()] for more details. For the `tidy` method, these are not currently used.

outcome

A single character string that specifies a single categorical variable to be used as the class.

role

For model terms created by this step, what analysis role should they be assigned?. By default, the function assumes that resulting distances will be used as predictors in a model.

trained

A logical to indicate if the quantities for preprocessing have been estimated.

threshold

A numeric value between 0 and 1 representing the percentile of best scoring features to select. For example `threshold = 0.9` will retain only predictors with scores in the top 90th percentile and a smaller threshold will select more features. Note that `top_p` and `threshold` are mutually exclusive but either can be used in conjunction with `cutoff` to select the top-ranked features and those that have filter scores that are larger than the cutoff value.

top_p

An integer that will be used to select the predictors with the largest ROC AUC values. A value of `NA` implies that this criterion will be ignored.

cutoff

A numeric value where predictors with _larger_ROC AUC scores than the cutoff will be retained. A value of `NA` implies that this criterion will be ignored.

exclude

A character vector of predictor names that will be removed from the data. This will be set when `prep()` is used on the recipe and should not be set by the user.

skip

A logical. Should the step be skipped when the recipe is baked by bake.recipe()? While all operations are baked when prep.recipe() is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when using skip = TRUE as it may affect the computations for subsequent operations.

id

A character string that is unique to this step to identify it.

x

A `step_select_roc` object.

Value

An updated version of `recipe` with the new step added to the sequence of existing steps (if any). For the `tidy` method, a tibble with a `terms` column for which predictors were removed.

Details

The recipe will stop if all of `top_p`, `threshold` and `cutoff` are left unspecified.

The ROC AUC will be set to be 1 - AUC if the value is less than 0.50.

Examples

data(cells, package = "modeldata")

rec <-
  recipe(class ~ ., data = cells[, -1]) %>%
  step_select_roc(all_predictors(), outcome = "class", top_p = 10, cutoff = 0.9) %>%
  prep()

rec %>% bake(all_predictors(), new_data = NULL) %>% names()
#>  [1] "avg_inten_ch_1"               "avg_inten_ch_2"              
#>  [3] "convex_hull_area_ratio_ch_1"  "convex_hull_perim_ratio_ch_1"
#>  [5] "entropy_inten_ch_1"           "fiber_width_ch_1"            
#>  [7] "shape_p_2_a_ch_1"             "total_inten_ch_1"            
#>  [9] "total_inten_ch_2"             "var_inten_ch_1"              

# Use ROC values to select but always keep at least one:
rec <-
  recipe(class ~ ., data = cells[, -1]) %>%
  step_select_roc(
    all_predictors(),
    outcome = "class",
    top_p = 1,
    cutoff = 0.99
  ) %>%
  prep()

rec %>% juice(all_predictors()) %>% names()
#> [1] "fiber_width_ch_1"