# libraries -------------------------------------------------------------------------------------------------------
library(testthat)
library(recipes)
library(tidy.outliers)
# setup -----------------------------------------------------------------------------------------------------------
rec_obj <-
recipe(mpg ~ ., data = mtcars) %>%
step_outliers_univariate(all_numeric_predictors(),combination_function = mean) %>%
prep(mtcars)
juice_result <- juice(rec_obj)
outlier_score <- juice_result$.outliers_univariate
# usual cases -----------------------------------------------------------------------------------------------------
test_scores(outlier_score)
# Test Passed
na_values_break_fun(step_outliers_univariate)
# Test Passed
# tidy method -----------------------------------------------------------------------------------------------------
tidy_result <- tidy(rec_obj, number = 1)
test_that("tidy probs work", {
expect_equal(nrow(mtcars), nrow(tidy_result))
})
# Test passed
# recipe without prep cases ---------------------------------------------------------------------------------------
tidy_rec_obj_not_prep <-
recipe(mpg ~ ., data = mtcars) %>%
step_outliers_univariate(all_numeric_predictors()) %>%
tidy(number = 1)
test_that("tidy probs go to NA", {
expect_equal(all(is.na(tidy_rec_obj_not_prep$outlier_score)), expected = T)
})
# Test passed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.