-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathtest_boost_tree.R
49 lines (39 loc) · 1.33 KB
/
test_boost_tree.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
hpc <- hpc_data[1:150, c(2:5, 8)]
# ------------------------------------------------------------------------------
test_that('updating', {
expect_snapshot(
boost_tree(trees = 1) %>%
set_engine("C5.0", noGlobalPruning = TRUE) %>%
update(trees = tune(), noGlobalPruning = tune())
)
})
test_that('bad input', {
expect_error(boost_tree(mode = "bogus"))
expect_error({
bt <- boost_tree(trees = -1) %>% set_engine("xgboost")
fit(bt, class ~ ., hpc)
})
expect_error({
bt <- boost_tree(min_n = -10) %>% set_engine("xgboost")
fit(bt, class ~ ., hpc)
})
expect_message(translate(boost_tree(mode = "classification"), engine = NULL))
expect_error(translate(boost_tree(formula = y ~ x)))
})
## -----------------------------------------------------------------------------
test_that('argument checks for data dimensions', {
spec <-
boost_tree(mtry = 1000, min_n = 1000, trees = 5) %>%
set_engine("spark") %>%
set_mode("classification")
args <- translate(spec)$method$fit$args
expect_equal(args$min_instances_per_node, expr(min_rows(1000, x)))
})
test_that('boost_tree can be fit with 1 predictor if validation is used', {
spec <- boost_tree(trees = 1) %>%
set_engine("xgboost", validation = 0.5) %>%
set_mode("regression")
expect_no_error(
fit(spec, mpg ~ disp, data = mtcars)
)
})