R/remove.R
step_outliers_remove.Rd
step_outliers_remove
creates a specification of a recipe
step that will calculate the score of the row of selected columns using an aggregation function and filter the resulting tibble based on the filter function
A recipe object. The step will be added to the sequence of operations for this recipe.
One or more selector functions to choose which
variables will be transformed. See selections()
for
more details. For the tidy
method, these are not
currently used.
a function that returns a value between 0 and 1 on an applied row
a value between 0 and 1 to decide outliers uses ">=" rule
placeholder for the tidy method
a placeholder for the vector of probabilities
name of the columns being operated on, after filtering they will be removed
not defined for this function
A logical to indicate if the quantities for preprocessing have been estimated.
A logical. Should the step be skipped when the
recipe is baked by bake()
? While all operations are baked
when prep()
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.
A character string that is unique to this step to identify it.
A step_outliers_remove
object.
An updated version of recipe
with the new step
added to the sequence of existing steps (if any), with the name on name_mutate
and the probabilities calculated. For the
tidy
method, a tibble with columns index
(the row indexes of the tibble), outliers
(the filtered outliers), aggregation_results
the "probabilities calculated".
All columns in the data are sampled and returned by juice()
and bake()
.
All columns used in this step must be numeric with no missing data.
When used in modeling, users should strongly consider using the
option skip = TRUE
so that this operation is not
conducted outside of the training set.
library(recipes)
library(tidy.outliers)
rec <-
recipe(mpg ~ ., data = mtcars) %>%
step_outliers_maha(all_numeric_predictors()) %>%
step_outliers_remove(contains(r"(.outliers)")) %>%
prep(mtcars)
bake(rec, new_data = NULL)
#> # A tibble: 28 × 11
#> cyl disp hp drat wt qsec vs am gear carb mpg
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 6 160 110 3.9 2.62 16.5 0 1 4 4 21
#> 2 6 160 110 3.9 2.88 17.0 0 1 4 4 21
#> 3 4 108 93 3.85 2.32 18.6 1 1 4 1 22.8
#> 4 6 258 110 3.08 3.22 19.4 1 0 3 1 21.4
#> 5 8 360 175 3.15 3.44 17.0 0 0 3 2 18.7
#> 6 6 225 105 2.76 3.46 20.2 1 0 3 1 18.1
#> 7 8 360 245 3.21 3.57 15.8 0 0 3 4 14.3
#> 8 4 147. 62 3.69 3.19 20 1 0 4 2 24.4
#> 9 6 168. 123 3.92 3.44 18.3 1 0 4 4 19.2
#> 10 6 168. 123 3.92 3.44 18.9 1 0 4 4 17.8
#> # … with 18 more rows
tidy(rec, number = 2)
#> # A tibble: 32 × 3
#> index outliers aggregation_results
#> <int> <lgl> <dbl>
#> 1 1 FALSE 0.411
#> 2 2 FALSE 0.374
#> 3 3 FALSE 0.222
#> 4 4 FALSE 0.192
#> 5 5 FALSE 0.124
#> 6 6 FALSE 0.350
#> 7 7 FALSE 0.481
#> 8 8 FALSE 0.493
#> 9 9 TRUE 0.985
#> 10 10 FALSE 0.737
#> # … with 22 more rows