forked from mlr-org/mlr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_classif_bartMachine.R
50 lines (44 loc) · 1.75 KB
/
test_classif_bartMachine.R
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
test_that("classif_bartMachine", {
skip_on_os("mac")
requirePackagesOrSkip("bartMachine", default.method = "load")
parset.list = list(
list(seed = getOption("mlr.debug.seed"), verbose = FALSE),
list(num_burn_in = 20L, num_iterations_after_burn_in = 50L,
run_in_sample = FALSE, seed = getOption("mlr.debug.seed"),
verbose = FALSE),
list(num_burn_in = 20L, num_iterations_after_burn_in = 50L, alpha = 0.8,
num_trees = 25L, run_in_sample = FALSE, seed = getOption("mlr.debug.seed"),
verbose = FALSE)
)
old.predicts.list = list()
old.probs.list = list()
for (i in seq_along(parset.list)) {
parset = parset.list[[i]]
x = binaryclass.train
y = factor(x[, binaryclass.class.col], levels = binaryclass.class.levs)
x[, binaryclass.class.col] = NULL
pars = list(X = x, y = y)
pars = c(pars, parset)
m = do.call(bartMachine::bartMachine, pars)
newx = binaryclass.test
newx[, binaryclass.class.col] = NULL
set.seed(getOption("mlr.debug.seed"))
p = predict(m, new_data = newx, type = "class")
set.seed(getOption("mlr.debug.seed"))
p2 = predict(m, new_data = newx, type = "prob")
old.predicts.list[[i]] = p
old.probs.list[[i]] = p2
}
set.seed(getOption("mlr.debug.seed"))
testSimpleParsets("classif.bartMachine", binaryclass.df,
binaryclass.target, binaryclass.train.inds,
old.predicts.list, parset.list)
set.seed(getOption("mlr.debug.seed"))
testProbParsets("classif.bartMachine", binaryclass.df,
binaryclass.target, binaryclass.train.inds,
old.probs.list, parset.list)
for (i in seq_along(parset.list)) {
expect_true(length(old.predicts.list[[i]]) == nrow(binaryclass.test))
expect_true(length(old.probs.list[[i]]) == nrow(binaryclass.test))
}
})