File: test_base_NoFeaturesModel.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,324 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("NoFeaturesModel", {
  task = subsetTask(multiclass.task, features = character(0))
  lrn = makeLearner("classif.lda", predict.type = "prob")
  m = train(lrn, task)
  expect_s3_class(m$learner.model, "NoFeaturesModel")
  expect_s3_class(m$learner, "classif.lda")
  expect_equal(m$learner$predict.type, "prob")

  p = predict(m, newdata = multiclass.df)
  expect_true(setequal(colnames(as.data.frame(p)),
    c("prob.setosa", "prob.virginica", "prob.versicolor", "truth", "response")))

  res = makeResampleDesc("CV", iter = 2)
  rf = resample(lrn, task, res)
  expect_true(setequal(colnames(as.data.frame(p)),
    c("prob.setosa", "prob.virginica", "prob.versicolor", "truth", "response")))

  task = subsetTask(regr.task, features = character(0))
  lrn = makeLearner("regr.lm")
  m = train(lrn, task)
  p = predict(m, newdata = regr.df)
  expect_true(all(p$data$response == mean(p$data$response)))

  rf = resample(lrn, task, res)$pred
  expect_equal(length(unique(rf$data$response)), 2)
})

test_that("NoFeaturesModel works with FilterWrapper", {
  lrn = makeLearner("classif.rpart")
  lrn = makeFilterWrapper(lrn, fw.method = "anova.test", fw.perc = 0.1)
  m = train(lrn, multiclass.task)
  p = predict(m, multiclass.task)
  expect_true(!is.na(performance(p, measures = getDefaultMeasure(multiclass.task))))
})