knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(dplyr)
library(tidy.outliers)
library(recipes)

One of neat applications of tidy.outliers is that you may want to model just use the outlier score outside of an workflow, this can be easily done as show.

Mahalanobis Score

Prep your recipe.

example_recipe <- 
  recipe(. ~ .,data = mtcars) |>
  step_outliers_maha(all_numeric())

Bake it with null.

example_recipe |>
  prep() |> 
  bake(new_data = NULL)

You can even give it a new name!

example_feature <- 
  recipe(. ~ .,data = mtcars) |>
  step_outliers_maha(all_numeric(),name_mutate = 'maha') |> 
  prep() |> 
  bake(new_data = NULL)

example_feature |> select(maha,everything())


brunocarlin/tidy.outliers documentation built on Feb. 22, 2023, 8:24 p.m.