File: test_regr_featureless.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 825 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("regr_featureless", {
  df = data.frame(
    y = c(1, 2, 3, 3, 3),
    x = rep(1, 5)
  )
  method = c("mean", "median")
  task = makeRegrTask(data = df, target = "y")

  # compute predictions manually
  expected.response = list(
    median = 3,
    mean = (1 + 2 + 3 + 3 + 3) / 5
  )

  for (m in method) {
    lrn = makeLearner("regr.featureless", method = m)
    mod = train(lrn, task)
    # test content of learner model
    expect_equal(getLearnerModel(mod)$response, expected.response[[m]])
    # test prediction works properly
    n = 10
    test = data.frame(rep(1, n))
    p = predict(mod, newdata = test)
    expect_equal(getPredictionResponse(p), rep(expected.response[[m]], n))
    # test that printer works correctly
    expect_output(print(lrn), "featureless")
    expect_output(print(lrn), m)
  }
})