Skip to content

Commit 0d9428f

Browse files
committed
Merge branch 'main' into release
2 parents 6eb1ee4 + acc8fba commit 0d9428f

File tree

1 file changed

+48
-41
lines changed

1 file changed

+48
-41
lines changed

tests/testthat/test_ensemble_fselect.R

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
test_that("ensemble feature selection works", {
22
task = tsk("sonar")
3-
efsr = ensemble_fselect(
4-
fselector = fs("random_search"),
5-
task = task,
6-
learners = lrns(c("classif.rpart", "classif.featureless")),
7-
init_resampling = rsmp("subsampling", repeats = 2),
8-
inner_resampling = rsmp("cv", folds = 3),
9-
measure = msr("classif.ce"),
10-
terminator = trm("evals", n_evals = 5)
11-
)
3+
with_seed(42, {
4+
efsr = ensemble_fselect(
5+
fselector = fs("random_search"),
6+
task = task,
7+
learners = lrns(c("classif.rpart", "classif.featureless")),
8+
init_resampling = rsmp("subsampling", repeats = 2),
9+
inner_resampling = rsmp("cv", folds = 3),
10+
measure = msr("classif.ce"),
11+
terminator = trm("evals", n_evals = 5)
12+
)
13+
})
1214

1315
expect_character(efsr$man)
1416
expect_data_table(efsr$result, nrows = 4)
@@ -33,16 +35,19 @@ test_that("ensemble feature selection works", {
3335

3436
# pareto_front
3537
pf = efsr$pareto_front()
36-
expect_data_table(pf)
38+
expect_data_table(pf, nrows = 3)
3739
expect_equal(names(pf), c("n_features", "classif.ce"))
38-
pf_pred = suppressWarnings(efsr$pareto_front(type = "estimated"))
40+
pf_pred = efsr$pareto_front(type = "estimated")
3941
expect_data_table(pf_pred, nrows = max(efsr$result$n_features))
4042
expect_equal(names(pf_pred), c("n_features", "classif.ce"))
4143

4244
# knee_points
4345
kps = efsr$knee_points()
44-
expect_data_table(kps, min.rows = 1)
46+
expect_data_table(kps, nrows = 1)
4547
expect_equal(names(kps), c("n_features", "classif.ce"))
48+
kpse = efsr$knee_points(type = "estimated")
49+
expect_data_table(kpse, nrows = 1)
50+
expect_true(kps$n_features != kpse$n_features)
4651

4752
# data.table conversion
4853
tab = as.data.table(efsr)
@@ -51,16 +56,18 @@ test_that("ensemble feature selection works", {
5156

5257
test_that("ensemble feature selection works without benchmark result", {
5358
task = tsk("sonar")
54-
efsr = ensemble_fselect(
55-
fselector = fs("random_search"),
56-
task = task,
57-
learners = lrns(c("classif.rpart", "classif.featureless")),
58-
init_resampling = rsmp("subsampling", repeats = 2),
59-
inner_resampling = rsmp("cv", folds = 3),
60-
measure = msr("classif.ce"),
61-
terminator = trm("evals", n_evals = 5),
62-
store_benchmark_result = FALSE
63-
)
59+
with_seed(42, {
60+
efsr = ensemble_fselect(
61+
fselector = fs("random_search"),
62+
task = task,
63+
learners = lrns(c("classif.rpart", "classif.featureless")),
64+
init_resampling = rsmp("subsampling", repeats = 2),
65+
inner_resampling = rsmp("cv", folds = 3),
66+
measure = msr("classif.ce"),
67+
terminator = trm("evals", n_evals = 3),
68+
store_benchmark_result = FALSE
69+
)
70+
})
6471

6572
expect_character(efsr$man)
6673
expect_data_table(efsr$result, nrows = 4)
@@ -84,15 +91,12 @@ test_that("ensemble feature selection works without benchmark result", {
8491

8592
# pareto_front
8693
pf = efsr$pareto_front()
87-
expect_data_table(pf)
94+
expect_data_table(pf, nrows = 3)
8895
expect_equal(names(pf), c("n_features", "classif.ce"))
89-
pf_pred = suppressWarnings(efsr$pareto_front(type = "estimated"))
90-
expect_data_table(pf_pred, nrows = max(efsr$result$n_features))
91-
expect_equal(names(pf_pred), c("n_features", "classif.ce"))
9296

9397
# knee_points
94-
kps = efsr$knee_points(type = "estimated")
95-
expect_data_table(kps, min.rows = 1)
98+
kps = efsr$knee_points()
99+
expect_data_table(kps, nrows = 1)
96100
expect_equal(names(kps), c("n_features", "classif.ce"))
97101

98102
# data.table conversion
@@ -102,15 +106,17 @@ test_that("ensemble feature selection works without benchmark result", {
102106

103107
test_that("ensemble feature selection works with rfe", {
104108
task = tsk("sonar")
105-
efsr = ensemble_fselect(
106-
fselector = fs("rfe", n_features = 2, feature_fraction = 0.8),
107-
task = task,
108-
learners = lrns(c("classif.rpart", "classif.featureless")),
109-
init_resampling = rsmp("subsampling", repeats = 2),
110-
inner_resampling = rsmp("cv", folds = 3),
111-
measure = msr("classif.ce"),
112-
terminator = trm("none")
113-
)
109+
with_seed(42, {
110+
efsr = ensemble_fselect(
111+
fselector = fs("rfe", n_features = 2, feature_fraction = 0.8),
112+
task = task,
113+
learners = lrns(c("classif.rpart", "classif.featureless")),
114+
init_resampling = rsmp("subsampling", repeats = 2),
115+
inner_resampling = rsmp("cv", folds = 3),
116+
measure = msr("classif.ce"),
117+
terminator = trm("none")
118+
)
119+
})
114120

115121
expect_character(efsr$man)
116122
expect_data_table(efsr$result, nrows = 4)
@@ -135,15 +141,15 @@ test_that("ensemble feature selection works with rfe", {
135141

136142
# pareto_front
137143
pf = efsr$pareto_front()
138-
expect_data_table(pf)
144+
expect_data_table(pf, nrows = 4)
139145
expect_equal(names(pf), c("n_features", "classif.ce"))
140-
pf_pred = suppressWarnings(efsr$pareto_front(type = "estimated"))
146+
pf_pred = efsr$pareto_front(type = "estimated")
141147
expect_data_table(pf_pred, nrows = max(efsr$result$n_features))
142148
expect_equal(names(pf_pred), c("n_features", "classif.ce"))
143149

144150
# knee_points
145151
kps = efsr$knee_points(type = "estimated")
146-
expect_data_table(kps, min.rows = 1)
152+
expect_data_table(kps, nrows = 1)
147153
expect_equal(names(kps), c("n_features", "classif.ce"))
148154

149155
# data.table conversion
@@ -190,7 +196,8 @@ test_that("different callbacks can be set", {
190196
)
191197

192198
efsr = ensemble_fselect(
193-
fselector = fs("rfe", n_features = 2, feature_fraction = 0.8),
199+
# 4-5 evaluations on sonar
200+
fselector = fs("rfe", n_features = 25, feature_fraction = 0.8),
194201
task = tsk("sonar"),
195202
learners = lrns(c("classif.rpart", "classif.featureless")),
196203
init_resampling = rsmp("subsampling", repeats = 2),

0 commit comments

Comments
 (0)