Skip to content

Commit a6ac07e

Browse files
bmihaljevicpat-s
authored andcommitted
A simple fix for occasional errors when using sffs (#2486)
* This fixes #2485 * add a test for the #2485 fix * conform coding style and reduce test time * Update test_featsel_selectFeaturesSequential.R * NEWS for #2486
1 parent 426511c commit a6ac07e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ In this case, the package name is omitted.
6060
* The FeatSelResult object now contains an additional slot `x.bit.names` that stores the optimal bits
6161
* The slot `x` now always contains the real feature names and not the bit.names
6262
* This fixes a bug and makes `makeFeatSelWrapper` usable with custom `bit.names`.
63+
* Fixed a bug due to which `sffs` crashed in some cases (@bmihaljevic, #2486)
6364

6465
# mlr 2.13:
6566

R/selectFeaturesSequential.R

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ selectFeaturesSequential = function(learner, task, resampling, measures, bit.nam
9393
state2 = seq.step(!forward, state, gns, compare)
9494
if (!is.null(state2)) {
9595
state = state2
96+
state$x = unlist(state$x)
9697
fail = 0
9798
} else {
9899
fail = fail + 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
context("selectFeaturesSequential")
2+
3+
# This used to cause an error. Now ensure it does not.
4+
test_that("no crash with sffs", {
5+
p = mlbench::mlbench.waveform(1000)
6+
dataset = as.data.frame(p)
7+
dataset = droplevels(subset(dataset, classes != 3))
8+
9+
mCT = makeClassifTask(data = dataset, target = "classes")
10+
ctrl = makeFeatSelControlSequential(method = "sffs", maxit = NA,alpha = 0.001)
11+
mL = makeLearner("classif.logreg", predict.type = "prob")
12+
inner = makeResampleDesc("Holdout",stratify = TRUE)
13+
lrn = makeFeatSelWrapper(mL, resampling = inner, control = ctrl)
14+
outer = makeResampleDesc("CV", iters = 2, stratify = TRUE)
15+
# No error occurs
16+
expect_error(resample(lrn, mCT, outer, extract = getFeatSelResult, measures = list(mlr::auc, mlr::acc, mlr::brier), models=TRUE),
17+
NA)
18+
})

0 commit comments

Comments
 (0)