library(testthat)
library(recipes)
library(tibble)
library(parsnip)
data("iris")
test_that("step_select_vip, execution using top_p", {
skip_if_not_installed("ranger")
irisX <- iris[-5]
y <- iris$Species
base_model <- rand_forest(mode = "classification") %>%
set_engine("ranger", importance = "permutation")
rec <- iris %>%
recipe(Species ~.) %>%
step_select_vip(
all_predictors(),
outcome = "Species",
model = base_model,
top_p = 2
)
prepped <- prep(rec)
selected <- juice(prepped)
expect_length(names(selected), 3)
})
test_that("step_select_vip, execution using threshold", {
skip_if_not_installed("ranger")
irisX <- iris[-5]
y <- iris$Species
base_model <- rand_forest(mode = "classification") %>%
set_engine("ranger", importance = "permutation")
# test selection by retaining features with scores >= 50th percentile
rec <- iris %>%
recipe(Species ~.) %>%
step_select_vip(
all_predictors(),
outcome = "Species",
model = base_model,
threshold = 0.5
)
prepped <- prep(rec)
selected <- juice(prepped)
expect_length(names(selected), 3)
# test selection by retaining features with scores in 90th percentile
rec <- iris %>%
recipe(Species ~.) %>%
step_select_vip(
all_predictors(),
outcome = "Species",
model = base_model,
threshold = 0.9
)
prepped <- prep(rec)
selected <- juice(prepped)
expect_length(names(selected), 2)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.