tests/testthat/test_FilterInformationGain.R

test_that("FilterInformationGain handles features with only missings gracefully", {
  data = tsk("mtcars")$data()
  data[, wt := NA]
  task = as_task_regr(data, target = "mpg")

  scores = flt("information_gain")$calculate(task)$scores

  expect_numeric(scores, any.missing = FALSE)
  expect_lte(scores["wt"], 1e-8)
})

test_that("FilterInformationGain handles features with only missings gracefully", {
  data = tsk("iris")$data()
  data[, Sepal.Length := NA]
  task = as_task_classif(data, target = "Species")

  scores = flt("information_gain")$calculate(task)$scores

  expect_numeric(scores, any.missing = FALSE)
  expect_lte(scores["Sepal.Length"], 1e-8)
})

Try the mlr3filters package in your browser

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

mlr3filters documentation built on Feb. 16, 2023, 7:29 p.m.