File: test_base_capLargeValues.R

package info (click to toggle)
r-cran-mlr 2.19.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,392 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (41 lines) | stat: -rwxr-xr-x 1,472 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

test_that("capLargeValues.data.frame", {

  # capLargeValues works
  d1 = data.frame(x = 1:10, y = c(1:9, Inf), z = c(-11:-20))
  d2 = capLargeValues(d1, threshold = 10, impute = 10)
  expect_equal(d2, data.frame(x = 1:10, y = c(1:10), z = rep(-10, 10)))

  d2 = capLargeValues(d1, threshold = 50, impute = 10, cols = "y")
  expect_equal(d2, data.frame(x = 1:10, y = c(1:9, 10), z = c(-11:-20)))

  d2 = capLargeValues(d1, threshold = 10, impute = 2, cols = "z")
  expect_equal(d2, data.frame(x = 1:10, y = c(1:9, Inf), z = rep(-2, 10)))

  # check arg target
  d1$tar = 11:20
  d2 = capLargeValues(d1, target = "tar", threshold = 10, impute = 10)
  expect_equal(d2, data.frame(x = 1:10, y = c(1:10), z = rep(-10, 10),
    tar = 11:20))

  # check arg what
  d1 = data.frame(x = c(-10, 1, 10))
  d2 = capLargeValues(d1, threshold = 9, what = "abs")
  expect_equal(d2, data.frame(x = c(-9, 1, 9)))

  d2 = capLargeValues(d1, threshold = 9, what = "pos")
  expect_equal(d2, data.frame(x = c(-10, 1, 9)))

  d2 = capLargeValues(d1, threshold = 9, what = "neg")
  expect_equal(d2, data.frame(x = c(-9, 1, 10)))
})

test_that("capLargeValues.Task", {
  d1 = data.frame(x = 1:10, y = 2:11, z = -11:-20, tar = 1:10)
  tsk = makeRegrTask(data = d1, target = "tar")
  capped.tsk = capLargeValues(tsk, threshold = 10, impute = 10)
  capped.d1 = getTaskData(capped.tsk)
  d2 = data.frame(x = 1:10, y = c(2:10, 10), z = rep(-10, 10),
    tar = 1:10)
  expect_equal(capped.d1, d2)
})