Abstract FSelector
class that implements the base functionality each
fselector must provide. A FSelector
object describes the feature selection
strategy, i.e. how to optimize the black-box function and its feasible set
defined by the FSelectInstanceSingleCrit / FSelectInstanceMultiCrit object.
A fselector must write its result into the FSelectInstanceSingleCrit /
FSelectInstanceMultiCrit using the assign_result
method of the
bbotk::OptimInstance at the end of its selection in order to store the best
selected feature subset and its estimated performance vector.
.optimize(instance)
-> NULL
Abstract base method. Implement to specify feature selection of your
subclass. See technical details sections.
.assign_result(instance)
-> NULL
Abstract base method. Implement to specify how the final feature subset is
selected. See technical details sections.
A subclass is implemented in the following way:
Inherit from FSelector
.
Specify the private abstract method $.optimize()
and use it to call into
your optimizer.
You need to call instance$eval_batch()
to evaluate feature subsets.
The batch evaluation is requested at the FSelectInstanceSingleCrit /
FSelectInstanceMultiCrit object instance
, so each batch is possibly
executed in parallel via mlr3::benchmark()
, and all evaluations are stored
inside of instance$archive
.
Before the batch evaluation, the bbotk::Terminator is checked, and if it is
positive, an exception of class "terminated_error"
is generated. In the
later case the current batch of evaluations is still stored in instance
,
but the numeric scores are not sent back to the handling optimizer as it has
lost execution control.
After such an exception was caught we select the best feature subset from
instance$archive
and return it.
Note that therefore more points than specified by the bbotk::Terminator may be evaluated, as the Terminator is only checked before a batch evaluation, and not in-between evaluation in a batch. How many more depends on the setting of the batch size.
Overwrite the private super-method .assign_result()
if you want to decide
yourself how to estimate the final feature subset in the instance and its
estimated performance. The default behavior is: We pick the best
resample-experiment, regarding the given measure, then assign its
feature subset and aggregated performance to the instance.
param_set
param_classes
(character()
).
properties
(character()
).
packages
(character()
).
new()
Creates a new instance of this R6 class.
FSelector$new(param_set, properties, packages = character(0))
param_set
paradox::ParamSet
Set of control parameters for fselector.
properties
(character()
)
Set of properties of the fselector. Must be a subset of
mlr_reflections$fselect_properties
.
packages
(character()
)
Set of required packages. Note that these packages will be loaded via
requireNamespace()
, and are not attached.
format()
Helper for print outputs.
FSelector$format()
(character()
).
print()
Print method.
FSelector$print()
(character()
).
optimize()
Performs the feature selection on a FSelectInstanceSingleCrit or FSelectInstanceMultiCrit until termination. The single evaluations will be written into the ArchiveFSelect that resides in the FSelectInstanceSingleCrit / FSelectInstanceMultiCrit. The result will be written into the instance object.
FSelector$optimize(inst)
clone()
The objects of this class are cloneable with this method.
FSelector$clone(deep = FALSE)
deep
Whether to make a deep clone.
library(mlr3) terminator = trm("evals", n_evals = 3) instance = FSelectInstanceSingleCrit$new( task = tsk("iris"), learner = lrn("classif.rpart"), resampling = rsmp("holdout"), measure = msr("classif.ce"), terminator = terminator ) # swap this line to use a different FSelector fselector = fs("random_search") # \donttest{ # modifies the instance by reference fselector$optimize(instance)#> Petal.Length Petal.Width Sepal.Length Sepal.Width features #> 1: TRUE FALSE TRUE FALSE Petal.Length,Sepal.Length #> classif.ce #> 1: 0.02# returns best feature subset and best performance instance$result#> Petal.Length Petal.Width Sepal.Length Sepal.Width features #> 1: TRUE FALSE TRUE FALSE Petal.Length,Sepal.Length #> classif.ce #> 1: 0.02# allows access of data.table / benchmark result of full path of all evaluations instance$archive# }#> <ArchiveFSelect> #> Petal.Length Petal.Width Sepal.Length Sepal.Width classif.ce #> 1: TRUE FALSE TRUE FALSE 0.02 #> 2: TRUE TRUE TRUE TRUE 0.02 #> 3: TRUE TRUE TRUE TRUE 0.02 #> 4: FALSE FALSE TRUE FALSE 0.34 #> 5: TRUE TRUE TRUE TRUE 0.02 #> 6: TRUE TRUE FALSE FALSE 0.02 #> 7: TRUE TRUE TRUE TRUE 0.02 #> 8: FALSE FALSE TRUE FALSE 0.34 #> 9: TRUE FALSE FALSE FALSE 0.02 #> 10: TRUE TRUE TRUE FALSE 0.02 #> uhash timestamp batch_nr #> 1: 7a740b59-3d1b-46fb-abaa-5bf7f3e82ca6 2021-03-21 04:30:31 1 #> 2: 27874c12-80b7-4958-8c08-2f88af0a72c9 2021-03-21 04:30:31 1 #> 3: 456d783d-4284-4f18-9e93-a8cb634b36fb 2021-03-21 04:30:31 1 #> 4: 78541a8a-7d3a-44c7-8616-4c1bfc3ee44c 2021-03-21 04:30:31 1 #> 5: 91087df7-95d8-4b5e-a152-189ff34b93bf 2021-03-21 04:30:31 1 #> 6: 9383ed59-a7b5-491d-bdb8-16f050d18ec2 2021-03-21 04:30:31 1 #> 7: b81752c8-cc2b-4bfe-9de8-cf8558b93d44 2021-03-21 04:30:31 1 #> 8: 635674b2-96c0-4721-8bca-b5343ac4221a 2021-03-21 04:30:31 1 #> 9: 629dc730-101e-4888-b1c2-dae9881cfde9 2021-03-21 04:30:31 1 #> 10: ae9a4d21-6024-4202-bdba-b320ad35c010 2021-03-21 04:30:31 1