1
1
test_that(" ensemble feature selection works" , {
2
2
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
+ })
12
14
13
15
expect_character(efsr $ man )
14
16
expect_data_table(efsr $ result , nrows = 4 )
@@ -33,16 +35,19 @@ test_that("ensemble feature selection works", {
33
35
34
36
# pareto_front
35
37
pf = efsr $ pareto_front()
36
- expect_data_table(pf )
38
+ expect_data_table(pf , nrows = 3 )
37
39
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" )
39
41
expect_data_table(pf_pred , nrows = max(efsr $ result $ n_features ))
40
42
expect_equal(names(pf_pred ), c(" n_features" , " classif.ce" ))
41
43
42
44
# knee_points
43
45
kps = efsr $ knee_points()
44
- expect_data_table(kps , min.rows = 1 )
46
+ expect_data_table(kps , nrows = 1 )
45
47
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 )
46
51
47
52
# data.table conversion
48
53
tab = as.data.table(efsr )
@@ -51,16 +56,18 @@ test_that("ensemble feature selection works", {
51
56
52
57
test_that(" ensemble feature selection works without benchmark result" , {
53
58
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
+ })
64
71
65
72
expect_character(efsr $ man )
66
73
expect_data_table(efsr $ result , nrows = 4 )
@@ -84,15 +91,12 @@ test_that("ensemble feature selection works without benchmark result", {
84
91
85
92
# pareto_front
86
93
pf = efsr $ pareto_front()
87
- expect_data_table(pf )
94
+ expect_data_table(pf , nrows = 3 )
88
95
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" ))
92
96
93
97
# 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 )
96
100
expect_equal(names(kps ), c(" n_features" , " classif.ce" ))
97
101
98
102
# data.table conversion
@@ -102,15 +106,17 @@ test_that("ensemble feature selection works without benchmark result", {
102
106
103
107
test_that(" ensemble feature selection works with rfe" , {
104
108
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
+ })
114
120
115
121
expect_character(efsr $ man )
116
122
expect_data_table(efsr $ result , nrows = 4 )
@@ -135,15 +141,15 @@ test_that("ensemble feature selection works with rfe", {
135
141
136
142
# pareto_front
137
143
pf = efsr $ pareto_front()
138
- expect_data_table(pf )
144
+ expect_data_table(pf , nrows = 4 )
139
145
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" )
141
147
expect_data_table(pf_pred , nrows = max(efsr $ result $ n_features ))
142
148
expect_equal(names(pf_pred ), c(" n_features" , " classif.ce" ))
143
149
144
150
# knee_points
145
151
kps = efsr $ knee_points(type = " estimated" )
146
- expect_data_table(kps , min.rows = 1 )
152
+ expect_data_table(kps , nrows = 1 )
147
153
expect_equal(names(kps ), c(" n_features" , " classif.ce" ))
148
154
149
155
# data.table conversion
@@ -190,7 +196,8 @@ test_that("different callbacks can be set", {
190
196
)
191
197
192
198
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 ),
194
201
task = tsk(" sonar" ),
195
202
learners = lrns(c(" classif.rpart" , " classif.featureless" )),
196
203
init_resampling = rsmp(" subsampling" , repeats = 2 ),
0 commit comments