tests/testthat/test_cpo_smote.R

context("cpoSmote test")

test_that("cpoSmote works as expected", {

  set.seed(123)
  t1 = pid.task %>>% cpoSmote()

  ratio = do.call(`/`, as.list(getTaskDesc(pid.task)$class.distribution))
  if (ratio < 1) {
    ratio = 1 / ratio
  }
  set.seed(123)
  t2 = pid.task %>>% cpoSmote(ratio)

  expect_equal(t1, t2)

  set.seed(123)
  t1 = pid.task %>>% cpoSmote(alt.logic = TRUE)

  ratio = do.call(`/`, as.list(getTaskDesc(pid.task)$class.distribution))
  if (ratio < 1) {
    ratio = 1 / ratio
  }
  set.seed(123)
  t2 = pid.task %>>% cpoSmote(ratio, alt.logic = TRUE)

  expect_equal(t1, t2)

  set.seed(123)
  x1 = cpo.df1c %>>% cpoSmote(nn = 1)
  set.seed(123)
  x2 = cpo.df1c %>>% cpoSmote(2, nn = 1)
  expect_equal(x1, x2)

  set.seed(123)
  smitten = smote(pid.task, ratio, 6, FALSE, TRUE)

  set.seed(123)
  t3 = pid.task %>>% cpoSmote(nn = 6, standardize = FALSE, alt.logic = TRUE)
  expect_equal(smitten, t3)


})

Try the mlrCPO package in your browser

Any scripts or data that you put into this service are public.

mlrCPO documentation built on Nov. 18, 2022, 1:05 a.m.