Skip to contents

The FSelectInstanceSingleCrit specifies a feature selection problem for FSelectors. The function fsi() creates a FSelectInstanceSingleCrit and the function fselect() creates an instance internally.

The instance contains an ObjectiveFSelect object that encodes the black box objective function a FSelector has to optimize. The instance allows the basic operations of querying the objective at design points ($eval_batch()). This operation is usually done by the FSelector. Evaluations of feature subsets are performed in batches by calling mlr3::benchmark() internally. The evaluated feature subsets are stored in the Archive ($archive). Before a batch is evaluated, the bbotk::Terminator is queried for the remaining budget. If the available budget is exhausted, an exception is raised, and no further evaluations can be performed from this point on. The FSelector is also supposed to store its final result, consisting of a selected feature subset and associated estimated performance values, by calling the method instance$assign_result().

Resources

Analysis

For analyzing the feature selection results, it is recommended to pass the archive to as.data.table(). The returned data table is joined with the benchmark result which adds the mlr3::ResampleResult for each feature set.

The archive provides various getters (e.g. $learners()) to ease the access. All getters extract by position (i) or unique hash (uhash). For a complete list of all getters see the methods section.

The benchmark result ($benchmark_result) allows to score the feature sets again on a different measure. Alternatively, measures can be supplied to as.data.table().

Super classes

bbotk::OptimInstance -> bbotk::OptimInstanceSingleCrit -> FSelectInstanceSingleCrit

Active bindings

result_feature_set

(character())
Feature set for task subsetting.

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage

FSelectInstanceSingleCrit$new(
  task,
  learner,
  resampling,
  measure,
  terminator,
  store_benchmark_result = TRUE,
  store_models = FALSE,
  check_values = FALSE
)

Arguments

task

(mlr3::Task)
Task to operate on.

learner

(mlr3::Learner)
Learner to optimize the feature subset for.

resampling

(mlr3::Resampling)
Resampling that is used to evaluated the performance of the feature subsets. Uninstantiated resamplings are instantiated during construction so that all feature subsets are evaluated on the same data splits. Already instantiated resamplings are kept unchanged.

measure

(mlr3::Measure)
Measure to optimize. If NULL, default measure is used.

terminator

(Terminator)
Stop criterion of the feature selection.

store_benchmark_result

(logical(1))
Store benchmark result in archive?

store_models

(logical(1)). Store models in benchmark result?

check_values

(logical(1))
Check the parameters before the evaluation and the results for validity?


Method assign_result()

The FSelector writes the best found feature subset and estimated performance value here. For internal use.

Usage

FSelectInstanceSingleCrit$assign_result(xdt, y)

Arguments

xdt

(data.table::data.table())
x values as data.table. Each row is one point. Contains the value in the search space of the FSelectInstanceMultiCrit object. Can contain additional columns for extra information.

y

(numeric(1))
Optimal outcome.


Method print()

Printer.

Usage

FSelectInstanceSingleCrit$print(...)

Arguments

...

(ignored).


Method clone()

The objects of this class are cloneable with this method.

Usage

FSelectInstanceSingleCrit$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Feature selection on Palmer Penguins data set
task = tsk("penguins")
learner = lrn("classif.rpart")

# Construct feature selection instance
instance = fsi(
  task = task,
  learner = learner,
  resampling = rsmp("cv", folds = 3),
  measures = msr("classif.ce"),
  terminator = trm("evals", n_evals = 4)
)

# Choose optimization algorithm
fselector = fs("random_search", batch_size = 2)

# Run feature selection
fselector$optimize(instance)
#>    bill_depth bill_length body_mass flipper_length island  sex year
#> 1:       TRUE        TRUE      TRUE           TRUE   TRUE TRUE TRUE
#>                                                          features classif.ce
#> 1: bill_depth,bill_length,body_mass,flipper_length,island,sex,... 0.06397152

# Subset task to optimal feature set
task$select(instance$result_feature_set)

# Train the learner with optimal feature set on the full data set
learner$train(task)

# Inspect all evaluated sets
as.data.table(instance$archive)
#>    bill_depth bill_length body_mass flipper_length island   sex  year
#> 1:       TRUE        TRUE      TRUE           TRUE   TRUE  TRUE  TRUE
#> 2:       TRUE       FALSE      TRUE          FALSE   TRUE  TRUE  TRUE
#> 3:       TRUE       FALSE      TRUE           TRUE   TRUE FALSE  TRUE
#> 4:       TRUE        TRUE      TRUE           TRUE  FALSE  TRUE FALSE
#>    classif.ce runtime_learners           timestamp batch_nr warnings errors
#> 1: 0.06397152            0.198 2022-11-25 12:09:25        1        0      0
#> 2: 0.17714213            0.196 2022-11-25 12:09:25        1        0      0
#> 3: 0.15408085            0.202 2022-11-25 12:09:26        2        0      0
#> 4: 0.07556573            0.198 2022-11-25 12:09:26        2        0      0
#>         resample_result
#> 1: <ResampleResult[21]>
#> 2: <ResampleResult[21]>
#> 3: <ResampleResult[21]>
#> 4: <ResampleResult[21]>