Skip to content

Commit

Permalink
add n_resamples field + nicer obj print
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Oct 17, 2024
1 parent f2ccbda commit bea5e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/EnsembleFSResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
#'
#' @param ... (ignored).
print = function(...) {
catf(format(self))
catf("%s with %s learners and %s initial resamplings",
format(self), self$n_learners, self$n_resamples)
print(private$.result[, c("resampling_iteration", "learner_id", "n_features"), with = FALSE])
},

Expand Down Expand Up @@ -403,6 +404,13 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
measure = function(rhs) {
assert_ro_binding(rhs)
private$.measure_id
},

#' @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) {
assert_ro_binding(rhs)
uniqueN(self$result$resampling_iteration)
}
),

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_ensemble_fselect.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test_that("ensemble feature selection works", {
expect_benchmark_result(efsr$benchmark_result)
expect_equal(efsr$measure, "classif.ce")
expect_equal(efsr$n_learners, 2)
expect_equal(efsr$n_resamples, 2)

# stability
expect_number(efsr$stability(stability_measure = "jaccard"))
Expand Down Expand Up @@ -77,6 +78,7 @@ test_that("ensemble feature selection works without benchmark result", {
expect_null(efsr$benchmark_result)
expect_equal(efsr$measure, "classif.ce")
expect_equal(efsr$n_learners, 2)
expect_equal(efsr$n_resamples, 2)

# stability
expect_number(efsr$stability(stability_measure = "jaccard"))
Expand Down Expand Up @@ -127,6 +129,7 @@ test_that("ensemble feature selection works with rfe", {
expect_benchmark_result(efsr$benchmark_result)
expect_equal(efsr$measure, "classif.ce")
expect_equal(efsr$n_learners, 2)
expect_equal(efsr$n_resamples, 2)

# stability
expect_number(efsr$stability(stability_measure = "jaccard"))
Expand Down Expand Up @@ -185,6 +188,7 @@ test_that("EnsembleFSResult initialization", {
efsr = EnsembleFSResult$new(result = result, features = paste0("V", 1:20), measure_id = "classif.ce")
expect_class(efsr, "EnsembleFSResult")
expect_equal(efsr$n_learners, 3)
expect_equal(efsr$n_resamples, 3)
tab = as.data.table(efsr)
expect_data_table(tab)
expect_equal(names(tab), c("resampling_iteration", "learner_id", "n_features",
Expand Down

0 comments on commit bea5e39

Please sign in to comment.