Skip to content

Commit e389e08

Browse files
committed
add plotting tests for ranger
1 parent 618c6bd commit e389e08

File tree

2 files changed

+91
-4
lines changed

2 files changed

+91
-4
lines changed

inst/testdata/test_ranger.rda

557 Bytes
Binary file not shown.

tests/testthat/test_ranger.R

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ load(system.file("testdata/test_ranger.rda", package="randomForestExplainer", mu
55
# library(ranger)
66
# library(survival)
77
# set.seed(12345)
8-
# ranger_c <- ranger(Species ~ ., data = iris, importance = "impurity", num.trees = 2)
8+
# ranger_c <- ranger(Species ~ ., data = iris, importance = "impurity", num.trees = 2, probability = TRUE)
99
# ranger_r <- ranger(mpg ~ ., data = mtcars, importance = "impurity", num.trees = 2)
1010
# ranger_s <- ranger(Surv(futime, fustat) ~ ., data = ovarian, importance = "impurity", num.trees = 2)
11-
# save(ranger_c, ranger_r, ranger_s, file = "inst/testdata/test_ranger.rda")
12-
11+
# save(ranger_c, ranger_r, ranger_s, ovarian, file = "inst/testdata/test_ranger.rda")
1312

1413
context("Test ranger classification forests")
1514

@@ -24,7 +23,7 @@ test_that("important_variables works", {
2423
imp_vars <- important_variables(ranger_c, k = 3,
2524
measures = c("mean_min_depth", "impurity",
2625
"no_of_nodes", "times_a_root", "p_value"))
27-
expect_equal(imp_vars, c("Petal.Width", "Petal.Length", "Sepal.Length"))
26+
expect_equal(imp_vars, c("Petal.Width", "Sepal.Length", "Petal.Length"))
2827
})
2928

3029
test_that("min_depth_distribution works", {
@@ -39,6 +38,35 @@ test_that("min_depth_interactions works", {
3938
1.5)
4039
})
4140

41+
test_that("plot_multi_way_importance works", {
42+
p <- plot_multi_way_importance(ranger_c)
43+
expect_silent(print(p))
44+
})
45+
46+
test_that("plot_min_depth_distribution works", {
47+
p <- plot_min_depth_distribution(ranger_c)
48+
expect_silent(print(p))
49+
})
50+
51+
test_that("plot_min_depth_interactions works", {
52+
p <- plot_min_depth_interactions(ranger_c)
53+
expect_silent(print(p))
54+
})
55+
56+
test_that("plot_predict_interaction works", {
57+
p <- plot_predict_interaction(ranger_c, data = iris, variable1 = "Petal.Width", variable2 = "Petal.Length")
58+
expect_silent(print(p))
59+
})
60+
61+
test_that("plot_importance_ggpairs works", {
62+
p <- plot_importance_ggpairs(ranger_c)
63+
expect_silent(suppressMessages(print(p)))
64+
})
65+
66+
test_that("plot_importance_rankings works", {
67+
p <- plot_importance_rankings(ranger_c)
68+
expect_silent(suppressWarnings(suppressMessages(print(p))))
69+
})
4270

4371
context("Test ranger regression forests")
4472

@@ -69,6 +97,35 @@ test_that("min_depth_interactions works", {
6997
0.5)
7098
})
7199

100+
test_that("plot_multi_way_importance works", {
101+
p <- plot_multi_way_importance(ranger_r)
102+
expect_silent(suppressWarnings(print(p)))
103+
})
104+
105+
test_that("plot_min_depth_distribution works", {
106+
p <- plot_min_depth_distribution(ranger_r)
107+
expect_silent(print(p))
108+
})
109+
110+
test_that("plot_min_depth_interactions works", {
111+
p <- plot_min_depth_interactions(ranger_r)
112+
expect_silent(print(p))
113+
})
114+
115+
test_that("plot_predict_interaction works", {
116+
p <- plot_predict_interaction(ranger_r, data = mtcars, variable1 = "cyl", variable2 = "wt")
117+
expect_silent(print(p))
118+
})
119+
120+
test_that("plot_importance_ggpairs works", {
121+
p <- plot_importance_ggpairs(ranger_r)
122+
expect_silent(suppressWarnings(suppressMessages(print(p))))
123+
})
124+
125+
test_that("plot_importance_rankings works", {
126+
p <- plot_importance_rankings(ranger_c)
127+
expect_silent(suppressWarnings(suppressMessages(print(p))))
128+
})
72129

73130
context("Test ranger survival forests")
74131

@@ -98,3 +155,33 @@ test_that("min_depth_interactions works", {
98155
expect_equivalent(min_depth_int[min_depth_int$interaction == "age:ecog.ps", ]$mean_min_depth,
99156
0.5)
100157
})
158+
159+
test_that("plot_multi_way_importance works", {
160+
p <- plot_multi_way_importance(ranger_s)
161+
expect_silent(suppressWarnings(print(p)))
162+
})
163+
164+
test_that("plot_min_depth_distribution works", {
165+
p <- plot_min_depth_distribution(ranger_s)
166+
expect_silent(print(p))
167+
})
168+
169+
test_that("plot_min_depth_interactions works", {
170+
p <- plot_min_depth_interactions(ranger_s)
171+
expect_silent(print(p))
172+
})
173+
174+
test_that("plot_predict_interaction works", {
175+
p <- plot_predict_interaction(ranger_s, data = ovarian, variable1 = "age", variable2 = "ecog.ps")
176+
expect_silent(print(p))
177+
})
178+
179+
test_that("plot_importance_ggpairs works", {
180+
p <- plot_importance_ggpairs(ranger_s)
181+
expect_silent(suppressWarnings(suppressMessages(print(p))))
182+
})
183+
184+
test_that("plot_importance_rankings works", {
185+
p <- plot_importance_rankings(ranger_s)
186+
expect_silent(suppressWarnings(suppressMessages(print(p))))
187+
})

0 commit comments

Comments
 (0)