-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest_Resampler.R
More file actions
165 lines (143 loc) · 3.73 KB
/
test_Resampler.R
File metadata and controls
165 lines (143 loc) · 3.73 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# test-Resampler.R
# ::rtemis::
# EDG rtemis.org
# library(testthat)
# StratSubConfig ----
test_that("StratSubConfig succeeds", {
rsp <- StratSubConfig(
n = 10L,
stratify_var = NULL,
train_p = .75,
strat_n_bins = 4L,
id_strat = NULL,
seed = NULL
)
expect_s7_class(rsp, StratSubConfig)
})
# KFoldConfig ----
test_that("KFoldConfig succeeds", {
rsp <- KFoldConfig(
n = 10L,
stratify_var = NULL,
strat_n_bins = 4L,
id_strat = NULL,
seed = NULL
)
expect_s7_class(rsp, KFoldConfig)
})
# BootstrapConfig ----
test_that("BootstrapConfig succeeds", {
rsp <- BootstrapConfig(
n = 10L,
id_strat = NULL,
seed = NULL
)
expect_s7_class(rsp, BootstrapConfig)
})
# StratBootConfig ----
test_that("StratBootConfig succeeds", {
rsp <- StratBootConfig(
n = 10L,
stratify_var = NULL,
train_p = .75,
strat_n_bins = 4L,
target_length = NULL,
id_strat = NULL,
seed = NULL
)
expect_s7_class(rsp, StratBootConfig)
})
# LOOCVConfig ----
test_that("LOOCVConfig succeeds", {
rsp <- LOOCVConfig(
n = 10L
)
expect_s7_class(rsp, LOOCVConfig)
})
# CustomConfig ----
test_that("CustomConfig succeeds", {
rsp <- CustomConfig(
n = 10L
)
expect_s7_class(rsp, CustomConfig)
})
# setup_Resampler() defaults ----
test_that("setup_Resampler() succeeds", {
rsp <- setup_Resampler()
expect_s7_class(rsp, ResamplerConfig)
})
# setup_Resampler() kfold ----
test_that("setup_Resampler() kfold succeeds", {
rsp <- setup_Resampler(type = "KFold")
expect_s7_class(rsp, KFoldConfig)
})
# setup_Resampler() strat_sub ----
test_that("setup_Resampler() strat_sub succeeds", {
rsp <- setup_Resampler(type = "StratSub")
expect_s7_class(rsp, StratSubConfig)
})
# setup_Resampler() strat_boot ----
test_that("setup_Resampler() strat_boot succeeds", {
rsp <- setup_Resampler(type = "StratBoot")
expect_s7_class(rsp, StratBootConfig)
})
test_that("setup_Resampler() strat_boot fails with invalid train_p", {
expect_error(
setup_Resampler(type = "StratBoot", train_p = 1)
)
})
# setup_Resampler() bootstrap ----
test_that("setup_Resampler() bootstrap succeeds", {
rsp <- setup_Resampler(type = "Bootstrap")
expect_s7_class(rsp, BootstrapConfig)
})
# setup_Resampler() loocv ----
test_that("setup_Resampler() loocv succeeds", {
rsp <- setup_Resampler(type = "LOOCV")
expect_s7_class(rsp, LOOCVConfig)
})
# Resampler ----
test_that("Resampler() succeeds", {
res <- Resampler(
type = "Custom",
resamples = list(),
config = setup_Resampler()
)
expect_s7_class(res, Resampler)
})
# resample() vector ----
## KFold ----
test_that("resample() vector succeeds", {
res <- resample(iris[[1]], setup_Resampler(type = "KFold"))
expect_s7_class(res, Resampler)
})
## StratSub ----
test_that("resample() vector succeeds with StratSub", {
res <- resample(iris[[1]], setup_Resampler(type = "StratSub"))
expect_s7_class(res, Resampler)
})
## StratBoot ----
test_that("resample() vector succeeds with StratBoot", {
res <- resample(iris[[1]], setup_Resampler(type = "StratBoot"))
expect_s7_class(res, Resampler)
})
## Bootstrap ----
test_that("resample() vector succeeds with Bootstrap", {
res <- resample(iris[[1]], setup_Resampler(type = "Bootstrap"))
expect_s7_class(res, Resampler)
})
## LOOCV ----
test_that("resample() vector succeeds with LOOCV", {
res <- resample(iris[[1]], setup_Resampler(type = "LOOCV"))
expect_s7_class(res, Resampler)
})
# resample() data.frame ----
test_that("resample() data.frame succeeds", {
res <- resample(iris, setup_Resampler())
expect_s7_class(res, Resampler)
})
# resample() data.table ----
test_that("resample() data.table succeeds", {
res <- resample(as.data.table(iris), setup_Resampler())
expect_s7_class(res, Resampler)
})