File: test_base_setPredictType.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 (35 lines) | stat: -rwxr-xr-x 1,279 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

test_that("predict.type gets propagated", {
  inner = makeResampleDesc("Holdout")
  lrn1 = makeLearner("classif.rpart")
  ps = makeParamSet(makeNumericParam("cp", lower = 0.1, upper = 1))
  ctrl = makeTuneControlRandom(maxit = 2)
  lrn2 = makeTuneWrapper(lrn1, resampling = inner, control = ctrl, par.set = ps,
    measures = getDefaultMeasure(iris.task))
  expect_equal(lrn2$predict.type, "response")
  lrn2 = setPredictType(lrn2, "prob")
  expect_equal(lrn2$predict.type, "prob")

  m = train(lrn2, iris.task)
  p = predict(m, iris.task)
  prob = getPredictionProbabilities(p)
  expect_true(is.data.frame(prob) && nrow(prob) == nrow(iris))
})

test_that("predict.type works with BaggingWrapper, special case", {
  lrn1 = makeLearner("classif.rpart", predict.type = "prob")
  expect_error(makeBaggingWrapper(lrn1, bw.iters = 3), "response")

  lrn1 = makeLearner("classif.rpart")
  lrn2 = makeBaggingWrapper(lrn1, bw.iters = 3)
  expect_equal(lrn2$predict.type, "response")

  lrn2 = setPredictType(lrn2, "prob")
  expect_equal(lrn2$predict.type, "prob")
  expect_equal(lrn2$next.learner$predict.type, "response")

  m = train(lrn2, iris.task)
  p = predict(m, iris.task)
  prob = getPredictionProbabilities(p)
  expect_true(is.data.frame(prob) && nrow(prob) == nrow(iris))
})