tests/testthat/test-ResamplingRepeatedSpCVEnv.R

test_that("folds can be printed", {
  skip_if_not_installed("blockCV")

  task = test_make_twoclass_task()
  rsp = rsmp("repeated_spcv_env")
  rsp$param_set$values = list(folds = 3, repeats = 5, features = "p_1")
  rsp$instantiate(task)

  expect_equal(rsp$folds(4:8), c(1, 2, 3, 1, 2))
})

test_that("reps can be printed", {
  skip_if_not_installed("blockCV")

  task = test_make_twoclass_task()
  rsp = rsmp("repeated_spcv_env")
  rsp$param_set$values = list(folds = 3, repeats = 5, features = "p_1")
  rsp$instantiate(task)

  expect_equal(rsp$repeats(4:8), c(2, 2, 2, 3, 3))
})

test_that("resampling iterations equals folds * repeats", {
  skip_if_not_installed("blockCV")

  task = test_make_twoclass_task()
  rsp = rsmp("repeated_spcv_env", folds = 2, repeats = 5, features = "p_1")
  rsp$instantiate(task)

  expect_equal(rsp$iters, 10)
})

test_that("feature p_1 seperates the observations in folds of equal size", {
  skip_if_not_installed("blockCV")
  set.seed(1)

  task = test_make_twoclass_task()
  rsp = rsmp("repeated_spcv_env", folds = 2, repeats = 5, features = "p_1")
  rsp$instantiate(task)

  expect_equal(rsp$test_set(1), 19:36)
  expect_equal(rsp$train_set(1), 1:18)
  expect_equal(rsp$test_set(2), 1:18)
  expect_equal(rsp$train_set(2), 19:36)
})

test_that("non-numeric feature throws an error", {
  skip_if_not_installed("blockCV")
  task = test_make_twoclass_task(features = c("numeric", "factor"))
  rsp = rsmp("repeated_spcv_env", folds = 2, repeats = 5, features = "p_2")

  expect_error(rsp$instantiate(task))
})

test_that("non-existing feature throws an error", {
  skip_if_not_installed("blockCV")
  task = test_make_twoclass_task()
  rsp = rsmp("repeated_spcv_env", folds = 2, repeats = 5, features = "p_3")

  expect_error(rsp$instantiate(task))
})

Try the mlr3spatiotempcv package in your browser

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

mlr3spatiotempcv documentation built on Oct. 24, 2023, 5:07 p.m.