File: test_base_resample_holdout.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 (30 lines) | stat: -rwxr-xr-x 1,060 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

test_that("holdout instance works", {
  rin = makeResampleInstance(makeResampleDesc("Holdout", split = 0.25), size = 20)
  expect_equal(rin$size, 20)
  expect_equal(rin$desc$iters, 1)
  expect_equal(length(rin$train.inds), 1)
  expect_equal(length(rin$test.inds), 1)
  expect_equal(length(rin$train.inds[[1]]), 5)
  expect_equal(length(rin$test.inds[[1]]), 15)
})

test_that("holdout fixed instance works", {
  rin = makeFixedHoldoutInstance(1:5, 1:15, size = 20)
  expect_equal(rin$size, 20)
  expect_equal(rin$desc$iters, 1)
  expect_equal(length(rin$train.inds), 1)
  expect_equal(length(rin$test.inds), 1)
  expect_equal(length(rin$train.inds[[1]]), 5)
  expect_equal(length(rin$test.inds[[1]]), 15)
})

test_that("holdout test.join works somehow", {
  lrn = makeLearner("classif.rpart", predict.type = "prob")

  # for holdout test.join and test.mean should be the same
  rin = makeResampleDesc("Holdout")
  mm = list(setAggregation(auc, test.join), auc)
  r = resample(lrn, sonar.task, rin, measures = mm)
  expect_equal(as.integer(diff(r$aggr)), 0)
})