Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themis steps #21

Merged
merged 11 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Suggests:
sparklyr,
testthat (>= 3.0.0),
tidypredict,
themis,
workflows
Config/testthat/edition: 3
Encoding: UTF-8
Expand Down
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ S3method(orbital,model_fit)
S3method(orbital,model_spec)
S3method(orbital,recipe)
S3method(orbital,step_BoxCox)
S3method(orbital,step_adasyn)
S3method(orbital,step_bsmote)
S3method(orbital,step_center)
S3method(orbital,step_corr)
S3method(orbital,step_downsample)
S3method(orbital,step_dummy)
S3method(orbital,step_filter_missing)
S3method(orbital,step_impute_mean)
Expand All @@ -20,6 +23,7 @@ S3method(orbital,step_lag)
S3method(orbital,step_lincomb)
S3method(orbital,step_log)
S3method(orbital,step_mutate)
S3method(orbital,step_nearmiss)
S3method(orbital,step_normalize)
S3method(orbital,step_novel)
S3method(orbital,step_nzv)
Expand All @@ -29,10 +33,15 @@ S3method(orbital,step_range)
S3method(orbital,step_ratio)
S3method(orbital,step_rename)
S3method(orbital,step_rm)
S3method(orbital,step_rose)
S3method(orbital,step_scale)
S3method(orbital,step_select)
S3method(orbital,step_smote)
S3method(orbital,step_smotenc)
S3method(orbital,step_sqrt)
S3method(orbital,step_tomek)
S3method(orbital,step_unknown)
S3method(orbital,step_upsample)
S3method(orbital,step_zv)
S3method(orbital,workflow)
S3method(predict,orbital_class)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

* Support for `step_rename()` has been added. (#17)

* Support for `step_upsample()`, `step_smote()`, `step_smotenc()`, `step_bsmote()`, `step_adasyn()`, `step_rose()`, `step_downsample()`, `step_nearmiss()`, and `step_tomek()` has been added. (#21)

* `orbital()` now works on `tune::last_fit()` objects. (#13)

* `orbital_predict()` has been removed and replaced with the more idiomatic `predict()` method. (#10)
Expand Down
7 changes: 7 additions & 0 deletions R/step_adasyn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_adasyn <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_adasyn} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_bsmote.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_bsmote <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_bsmote} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_downsample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_downsample <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_downsample} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_nearmiss.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_nearmiss <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_nearmiss} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_rose.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_rose <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_rose} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_smote.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_smote <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_smote} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_smotenc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_smotenc <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_smotenc} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_tomek.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_tomek <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_tomek} when \\
{.arg skip} is {.code FALSE}."
)
}
7 changes: 7 additions & 0 deletions R/step_upsample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @export
orbital.step_upsample <- function(x, all_vars, ...) {
cli::cli_abort(
"{.fn orbital} method doesn't work for {.fn step_upsample} when \\
{.arg skip} is {.code FALSE}."
)
}
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_adasyn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_bsmote errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_bsmote()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_bsmote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_bsmote errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_bsmote()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_downsample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_downsample errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_downsample()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_nearmiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_nearmiss errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_nearmiss()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_rose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_rose errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_rose()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_smote.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_smote errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_smote()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_smotenc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_smotenc errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_smotenc()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_tomek.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_tomek errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_tomek()` when `skip` is `FALSE`.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/step_upsample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# step_upsample errors with skip = FALSE

Code
orbital(rec)
Condition
Error in `orbital()`:
! `orbital()` method doesn't work for `step_upsample()` when `skip` is `FALSE`.

60 changes: 60 additions & 0 deletions tests/testthat/test-step_adasyn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
test_that("step_adasyn works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")

mtcars <- dplyr::as_tibble(mtcars)
mtcars$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
themis::step_adasyn(vs, skip = TRUE) %>%
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

exp <- recipes::bake(rec, new_data = mtcars)
exp <- exp[names(res)]

expect_equal(res, exp)
})

test_that("step_adasyn errors with skip = FALSE", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")

mtcars <- dplyr::as_tibble(mtcars)
mtcars$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
themis::step_adasyn(vs, skip = FALSE) %>%
recipes::prep()

expect_snapshot(
error = TRUE,
orbital(rec)
)
})

test_that("spark - step_adasyn works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("sparklyr")
skip_if(is.na(testthat_spark_env_version()))

mtcars_adasyn <- dplyr::as_tibble(mtcars)
mtcars_adasyn$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars_adasyn) %>%
themis::step_adasyn(vs, skip = TRUE) %>%
recipes::prep()

res <- dplyr::mutate(mtcars_adasyn, !!!orbital_inline(orbital(rec)))
res$vs <- as.character(res$vs)

sc <- testthat_spark_connection()
mtcars_tbl <- testthat_tbl("mtcars_adasyn")

res_spark <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_spark, res)
})
60 changes: 60 additions & 0 deletions tests/testthat/test-step_bsmote.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
test_that("step_bsmote works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")

mtcars <- dplyr::as_tibble(mtcars)
mtcars$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
themis::step_bsmote(vs, skip = TRUE) %>%
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

exp <- recipes::bake(rec, new_data = mtcars)
exp <- exp[names(res)]

expect_equal(res, exp)
})

test_that("step_bsmote errors with skip = FALSE", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")

mtcars <- dplyr::as_tibble(mtcars)
mtcars$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
themis::step_bsmote(vs, skip = FALSE) %>%
recipes::prep()

expect_snapshot(
error = TRUE,
orbital(rec)
)
})

test_that("spark - step_bsmote works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("sparklyr")
skip_if(is.na(testthat_spark_env_version()))

mtcars_bsmote <- dplyr::as_tibble(mtcars)
mtcars_bsmote$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars_bsmote) %>%
themis::step_bsmote(vs, skip = TRUE) %>%
recipes::prep()

res <- dplyr::mutate(mtcars_bsmote, !!!orbital_inline(orbital(rec)))
res$vs <- as.character(res$vs)

sc <- testthat_spark_connection()
mtcars_tbl <- testthat_tbl("mtcars_bsmote")

res_spark <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_spark, res)
})
60 changes: 60 additions & 0 deletions tests/testthat/test-step_downsample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
test_that("step_downsample works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")

mtcars <- dplyr::as_tibble(mtcars)
mtcars$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
themis::step_downsample(vs, skip = TRUE) %>%
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

exp <- recipes::bake(rec, new_data = mtcars)
exp <- exp[names(res)]

expect_equal(res, exp)
})

test_that("step_downsample errors with skip = FALSE", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")

mtcars <- dplyr::as_tibble(mtcars)
mtcars$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
themis::step_downsample(vs, skip = FALSE) %>%
recipes::prep()

expect_snapshot(
error = TRUE,
orbital(rec)
)
})

test_that("spark - step_downsample works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("sparklyr")
skip_if(is.na(testthat_spark_env_version()))

mtcars_downsample <- dplyr::as_tibble(mtcars)
mtcars_downsample$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars_downsample) %>%
themis::step_downsample(vs, skip = TRUE) %>%
recipes::prep()

res <- dplyr::mutate(mtcars_downsample, !!!orbital_inline(orbital(rec)))
res$vs <- as.character(res$vs)

sc <- testthat_spark_connection()
mtcars_tbl <- testthat_tbl("mtcars_downsample")

res_spark <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_spark, res)
})
Loading
Loading