File: test_classif_adaboostm1.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 (64 lines) | stat: -rwxr-xr-x 2,242 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

test_that("classif_adaboostm1", {
  requirePackagesOrSkip("RWeka", default.method = "load")

  parset.list = list(
    list(),
    list(W = list(RWeka::J48, M = 30)),
    list(P = 100),
    list(I = 10, S = 1),
    list(I = 5, Q = FALSE)
  )

  old.predicts.list = list()
  old.probs.list = list()

  for (i in seq_along(parset.list)) {
    parset = parset.list[[i]]
    set.seed(getOption("mlr.debug.seed"))
    ctrl = do.call(RWeka::Weka_control, parset)
    m = RWeka::AdaBoostM1(formula = binaryclass.formula,
      data = binaryclass.train, control = ctrl)
    set.seed(getOption("mlr.debug.seed"))
    p = predict(m, newdata = binaryclass.test, type = "probability")
    old.probs.list[[i]] = p[, 1]
    old.predicts.list[[i]] = as.factor(binaryclass.class.levs[ifelse(p[, 2] > 0.5, 2, 1)])
  }

  testSimpleParsets("classif.adaboostm1", binaryclass.df, binaryclass.target,
    binaryclass.train.inds, old.predicts.list, parset.list)

  testProbParsets("classif.adaboostm1", binaryclass.df, binaryclass.target,
    binaryclass.train.inds, old.probs.list, parset.list)

  for (i in seq_along(parset.list)) {
    parset = parset.list[[i]]
    set.seed(getOption("mlr.debug.seed"))
    ctrl = do.call(RWeka::Weka_control, parset)
    m = RWeka::AdaBoostM1(formula = multiclass.formula, data = multiclass.train,
      control = ctrl)
    set.seed(getOption("mlr.debug.seed"))
    p = predict(m, newdata = multiclass.test, type = "class")
    set.seed(getOption("mlr.debug.seed"))
    p2 = predict(m, newdata = multiclass.test, type = "prob")
    old.predicts.list[[i]] = p
    old.probs.list[[i]] = p2

  }

  testSimpleParsets("classif.adaboostm1", multiclass.df, multiclass.target,
    multiclass.train.inds, old.predicts.list, parset.list)

  testProbParsets("classif.adaboostm1", multiclass.df, multiclass.target,
    multiclass.train.inds, old.probs.list, parset.list)

  tt = function(formula, data, subset, ...) {
    RWeka::AdaBoostM1(formula, data = data[subset, ],
      control = RWeka::Weka_control(...))
  }

  tp = function(model, newdata) predict(model, newdata, type = "class")

  testCVParsets("classif.adaboostm1", multiclass.df, multiclass.target, #
    tune.train = tt, tune.predict = tp, parset.list = parset.list)
})