Skip to content

Commit

Permalink
add active_measure field
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Nov 26, 2024
1 parent 3bd1772 commit 9e05dca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions R/EnsembleFSResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,18 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
}
},

#' @field active_measure (`character(1)`)\cr
#' Specifies the type of the active measure.
#' Can be one of the two:
#'
#' - `"outer"`: measure used in the test sets of the ensemble feature
#' selection process.
#' - `"inner"`: measure used for optimization and scoring the train sets.
active_measure = function(rhs) {
assert_ro_binding(rhs)
private$.active_measure
},

#' @field n_resamples (`character(1)`)\cr
#' Returns the number of times the task was initially resampled in the ensemble feature selection.
n_resamples = function(rhs) {
Expand Down
9 changes: 9 additions & 0 deletions man/ensemble_fs_result.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion tests/testthat/test_ensemble_fselect.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test_that("efs works", {
expect_measure(efsr$measure)
expect_equal(efsr$measure$id, "classif.ce")
expect_true(efsr$measure$minimize) # classification error
expect_equal(efsr$active_measure, "outer")
expect_equal(efsr$n_learners, 2)
expect_equal(efsr$n_resamples, 2)

Expand Down Expand Up @@ -62,6 +63,7 @@ test_that("efs works", {
efsr$set_active_measure(which = "inner")
expect_measure(efsr$measure)
expect_equal(efsr$measure$id, "classif.ce") # classification error also used for inner measure
expect_equal(efsr$active_measure, "inner")
pf_inner = efsr$pareto_front()
expect_data_table(pf_inner, nrows = 3) # pareto front has changed
expect_equal(names(pf_inner), c("n_features", "classif.ce_inner"))
Expand All @@ -71,6 +73,7 @@ test_that("efs works", {
expect_equal(names(kps_inner), c("n_features", "classif.ce_inner"))
# change to use outer measure again
efsr$set_active_measure(which = "outer")
expect_equal(efsr$active_measure, "outer")
pf_outer = efsr$pareto_front()
expect_equal(pf_outer, pf) # same measure, same pareto front

Expand Down Expand Up @@ -107,6 +110,7 @@ test_that("efs works with rfe", {
expect_measure(efsr$measure)
expect_equal(efsr$measure$id, "classif.acc")
expect_false(efsr$measure$minimize) # accuracy
expect_equal(efsr$active_measure, "outer")
expect_equal(efsr$n_learners, 2)
expect_equal(efsr$n_resamples, 2)

Expand All @@ -115,6 +119,7 @@ test_that("efs works with rfe", {
expect_measure(efsr$measure)
expect_equal(efsr$measure$id, "classif.ce") # no `_inner` end-fix here
expect_true(efsr$measure$minimize) # classification error
expect_equal(efsr$active_measure, "inner")

# stability
expect_number(efsr$stability(stability_measure = "jaccard"))
Expand All @@ -137,6 +142,7 @@ test_that("efs works with rfe", {

# change measure back to "outer"
efsr$set_active_measure(which = "outer")
expect_equal(efsr$active_measure, "outer")
pf_outer = efsr$pareto_front() # pareto front has used the accuracy measure
expect_equal(names(pf_outer), c("n_features", "classif.acc"))

Expand Down Expand Up @@ -200,13 +206,14 @@ test_that("EnsembleFSResult initialization", {
expect_measure(efsr$measure)
expect_equal(efsr$measure$id, "classif.ce")
expect_true(efsr$measure$minimize)
expect_equal(efsr$active_measure, "outer")
tab = as.data.table(efsr)
expect_data_table(tab)
expect_equal(names(tab), c("resampling_iteration", "learner_id", "n_features",
"features", "classif.ce", "classif.acc_inner"))
# change active measure
efsr$set_active_measure(which = "inner")
expect_equal(efsr$.__enclos_env__$private$.active_measure, "inner")
expect_equal(efsr$active_measure, "inner")
expect_measure(efsr$measure)
expect_equal(efsr$measure$id, "classif.acc")
expect_false(efsr$measure$minimize)
Expand Down

0 comments on commit 9e05dca

Please sign in to comment.