File: test_base_costsens.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 (36 lines) | stat: -rwxr-xr-x 1,119 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

test_that("costsens", {
  rdesc = makeResampleDesc("CV", iters = 2L)

  lrn = makeCostSensClassifWrapper(makeLearner("classif.rpart"))
  r = resample(lrn, costsens.task, rdesc)
  expect_true(!is.na(r$aggr))

  # check case where some costs are totally equal
  costs = costsens.costs
  costs[1, ] = 1
  costs[2, ] = 2
  task = makeCostSensTask(data = costsens.feat, costs = costs)
  r = resample(lrn, task, rdesc)
  expect_true(!is.na(r$aggr))

  # check case where all costs are totally equal
  costs[, ] = 1
  task = makeCostSensTask(data = costsens.feat, costs = costs)
  r = resample(lrn, task, rdesc)
  expect_true(!is.na(r$aggr))

  # check that hyperpars are propagated
  lrn2 = setHyperPars(lrn, minsplit = 50)
  m = train(lrn2, costsens.task)
  m2 = m$learner.model$next.model$learner.model
  expect_equal(m2$control$minsplit, 50)

  lrn = makeCostSensRegrWrapper(makeLearner("regr.rpart"))
  r = resample(lrn, costsens.task, rdesc)
  expect_true(!is.na(r$aggr))

  lrn = makeCostSensWeightedPairsWrapper(makeLearner("classif.rpart"))
  r = resample(lrn, costsens.task, rdesc)
  expect_true(!is.na(r$aggr))
})