File: test_base_ClassificationViaRegressionWrapper.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 (27 lines) | stat: -rwxr-xr-x 1,166 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

test_that("ClassificationViaRegressionWrapper predicts with response", {
  lrn1 = makeLearner("regr.rpart")
  lrn2 = makeClassificationViaRegressionWrapper(lrn1)

  m = train(lrn2, binaryclass.task, subset = binaryclass.train.inds)
  expect_true(!inherits(m, "FailureModel"))

  p = predict(m, task = binaryclass.task, subset = binaryclass.test.inds)
  expect_lt(0, performance(p, measures = mmce))
  expect_lt(performance(p, measures = mmce), 1)
  expect_equal(length(binaryclass.test.inds), length(getPredictionResponse(p)))
})

test_that("ClassificationViaRegressionWrapper predicts with prob", {
  lrn1 = makeLearner("regr.rpart")
  lrn2 = makeClassificationViaRegressionWrapper(lrn1, predict.type = "prob")

  m = train(lrn2, binaryclass.task, subset = binaryclass.train.inds)
  expect_true(!inherits(m, "FailureModel"))

  p = predict(m, task = binaryclass.task, subset = binaryclass.test.inds)
  expect_lt(0, performance(p, measures = mmce))
  expect_lt(performance(p, measures = mmce), 1)
  expect_equal(length(binaryclass.test.inds), length(getPredictionResponse(p)))
  expect_equal(length(binaryclass.test.inds), length(getPredictionProbabilities(p)))
})