Skip to content

Commit deabd37

Browse files
authored
fix(extract_inner_fselect_results): copy the result before adding columns (#172)
1 parent ba32ab4 commit deabd37

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# mlr3fselect (development version)
22

33
* fix: `ArchiveAsyncFSelect` pushed results with the removed `rush::Rush$push_results()` method.
4+
* fix: `extract_inner_fselect_results()` added the `iteration` and `fselect_instance` columns to the result of the inner `FSelectInstance` by reference, which created a circular reference between the instance and its own result (#172).
45
* fix: `fs("rfe")` and `fs("rfecv")` failed with an internal `data.table` error when `store_benchmark_result = FALSE` was set because the importance scores were read from the benchmark result of the archive (#169).
56
* fix: `fs("rfecv", recursive = FALSE)` failed with an internal `data.table` error because the importance scores of all resampling iterations were written to a single archive row (#168).
67
* fix: `fs("rfecv")` ignored the direction of the measure and selected the feature set size with the worst mean performance for minimizing measures such as `msr("classif.ce")` or `msr("regr.mse")`.

R/extract_inner_fselect_results.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ extract_inner_fselect_results.ResampleResult = function(x, fselect_instance = FA
6363
return(data.table())
6464
}
6565
tab = imap_dtr(rr$learners, function(learner, i) {
66-
data = setalloccol(learner$fselect_result)
66+
# copy the result, otherwise the columns below are added to the result of the instance
67+
data = copy(learner$fselect_result)
6768
set(data, j = "iteration", value = i)
6869
if (fselect_instance) {
6970
set(data, j = "fselect_instance", value = list(learner$fselect_instance))

tests/testthat/test_extract_inner_fselect_result.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,27 @@ test_that("extract_inner_fselect_results function works with benchmark and retur
377377
)
378378
expect_equal(unique(ibmr$experiment), c(1, 2))
379379
})
380+
381+
test_that("extract_inner_fselect_results does not modify the fselect result", {
382+
rr = fselect_nested(
383+
fs("random_search"),
384+
tsk("iris"),
385+
lrn("classif.rpart"),
386+
rsmp("holdout"),
387+
rsmp("cv", folds = 2),
388+
msr("classif.ce"),
389+
term_evals = 4
390+
)
391+
392+
columns = names(rr$learners[[1]]$fselect_result)
393+
394+
extract_inner_fselect_results(rr)
395+
expect_named(rr$learners[[1]]$fselect_result, columns)
396+
397+
extract_inner_fselect_results(rr, fselect_instance = TRUE)
398+
expect_named(rr$learners[[1]]$fselect_result, columns)
399+
400+
# the instance is not added again when it is not requested
401+
irr = extract_inner_fselect_results(rr)
402+
expect_names(names(irr), disjunct.from = "fselect_instance")
403+
})

0 commit comments

Comments
 (0)