
Feature Selection with Exhaustive Search
Source:R/FSelectorExhaustiveSearch.R
mlr_fselectors_exhaustive_search.Rd
Feature Selection using the Exhaustive Search Algorithm. Exhaustive Search generates all possible feature sets.
Details
The feature selection terminates itself when all feature sets are evaluated. It is not necessary to set a termination criterion.
Dictionary
This FSelector can be instantiated with the associated sugar function fs()
:
fs("exhaustive_search")
Control Parameters
max_features
integer(1)
Maximum number of features. By default, number of features in mlr3::Task.
Super class
mlr3fselect::FSelector
-> FSelectorExhaustiveSearch
Examples
# Feature Selection
# \donttest{
# retrieve task and load learner
task = tsk("penguins")
learner = lrn("classif.rpart")
# run feature selection on the Palmer Penguins data set
instance = fselect(
fselector = fs("exhaustive_search"),
task = task,
learner = learner,
resampling = rsmp("holdout"),
measure = msr("classif.ce"),
term_evals = 10
)
# best performing feature set
instance$result
#> bill_depth bill_length body_mass flipper_length island sex year
#> 1: FALSE TRUE FALSE FALSE TRUE FALSE FALSE
#> features classif.ce
#> 1: bill_length,island 0.04347826
# all evaluated feature sets
as.data.table(instance$archive)
#> bill_depth bill_length body_mass flipper_length island sex year
#> 1: TRUE FALSE FALSE FALSE FALSE FALSE FALSE
#> 2: FALSE TRUE FALSE FALSE FALSE FALSE FALSE
#> 3: FALSE FALSE TRUE FALSE FALSE FALSE FALSE
#> 4: FALSE FALSE FALSE TRUE FALSE FALSE FALSE
#> 5: FALSE FALSE FALSE FALSE TRUE FALSE FALSE
#> 6: FALSE FALSE FALSE FALSE FALSE TRUE FALSE
#> 7: FALSE FALSE FALSE FALSE FALSE FALSE TRUE
#> 8: TRUE TRUE FALSE FALSE FALSE FALSE FALSE
#> 9: TRUE FALSE TRUE FALSE FALSE FALSE FALSE
#> 10: TRUE FALSE FALSE TRUE FALSE FALSE FALSE
#> 11: TRUE FALSE FALSE FALSE TRUE FALSE FALSE
#> 12: TRUE FALSE FALSE FALSE FALSE TRUE FALSE
#> 13: TRUE FALSE FALSE FALSE FALSE FALSE TRUE
#> 14: FALSE TRUE TRUE FALSE FALSE FALSE FALSE
#> 15: FALSE TRUE FALSE TRUE FALSE FALSE FALSE
#> 16: FALSE TRUE FALSE FALSE TRUE FALSE FALSE
#> 17: FALSE TRUE FALSE FALSE FALSE TRUE FALSE
#> 18: FALSE TRUE FALSE FALSE FALSE FALSE TRUE
#> 19: FALSE FALSE TRUE TRUE FALSE FALSE FALSE
#> 20: FALSE FALSE TRUE FALSE TRUE FALSE FALSE
#> 21: FALSE FALSE TRUE FALSE FALSE TRUE FALSE
#> 22: FALSE FALSE TRUE FALSE FALSE FALSE TRUE
#> 23: FALSE FALSE FALSE TRUE TRUE FALSE FALSE
#> 24: FALSE FALSE FALSE TRUE FALSE TRUE FALSE
#> 25: FALSE FALSE FALSE TRUE FALSE FALSE TRUE
#> 26: FALSE FALSE FALSE FALSE TRUE TRUE FALSE
#> 27: FALSE FALSE FALSE FALSE TRUE FALSE TRUE
#> 28: FALSE FALSE FALSE FALSE FALSE TRUE TRUE
#> bill_depth bill_length body_mass flipper_length island sex year
#> classif.ce runtime_learners timestamp batch_nr warnings errors
#> 1: 0.30434783 0.008 2023-03-02 12:42:32 1 0 0
#> 2: 0.24347826 0.008 2023-03-02 12:42:32 1 0 0
#> 3: 0.32173913 0.008 2023-03-02 12:42:32 1 0 0
#> 4: 0.23478261 0.009 2023-03-02 12:42:32 1 0 0
#> 5: 0.27826087 0.008 2023-03-02 12:42:32 1 0 0
#> 6: 0.57391304 0.007 2023-03-02 12:42:32 1 0 0
#> 7: 0.57391304 0.007 2023-03-02 12:42:32 1 0 0
#> 8: 0.10434783 0.009 2023-03-02 12:42:33 2 0 0
#> 9: 0.28695652 0.007 2023-03-02 12:42:33 2 0 0
#> 10: 0.23478261 0.008 2023-03-02 12:42:33 2 0 0
#> 11: 0.22608696 0.008 2023-03-02 12:42:33 2 0 0
#> 12: 0.30434783 0.009 2023-03-02 12:42:33 2 0 0
#> 13: 0.30434783 0.008 2023-03-02 12:42:33 2 0 0
#> 14: 0.06956522 0.009 2023-03-02 12:42:33 2 0 0
#> 15: 0.08695652 0.031 2023-03-02 12:42:33 2 0 0
#> 16: 0.04347826 0.011 2023-03-02 12:42:33 2 0 0
#> 17: 0.24347826 0.011 2023-03-02 12:42:33 2 0 0
#> 18: 0.24347826 0.008 2023-03-02 12:42:33 2 0 0
#> 19: 0.24347826 0.009 2023-03-02 12:42:33 2 0 0
#> 20: 0.26086957 0.008 2023-03-02 12:42:33 2 0 0
#> 21: 0.30434783 0.009 2023-03-02 12:42:33 2 0 0
#> 22: 0.32173913 0.009 2023-03-02 12:42:33 2 0 0
#> 23: 0.15652174 0.009 2023-03-02 12:42:33 2 0 0
#> 24: 0.22608696 0.010 2023-03-02 12:42:33 2 0 0
#> 25: 0.23478261 0.008 2023-03-02 12:42:33 2 0 0
#> 26: 0.27826087 0.007 2023-03-02 12:42:33 2 0 0
#> 27: 0.33043478 0.007 2023-03-02 12:42:33 2 0 0
#> 28: 0.57391304 0.008 2023-03-02 12:42:33 2 0 0
#> classif.ce runtime_learners timestamp batch_nr warnings errors
#> features resample_result
#> 1: bill_depth <ResampleResult[21]>
#> 2: bill_length <ResampleResult[21]>
#> 3: body_mass <ResampleResult[21]>
#> 4: flipper_length <ResampleResult[21]>
#> 5: island <ResampleResult[21]>
#> 6: sex <ResampleResult[21]>
#> 7: year <ResampleResult[21]>
#> 8: bill_depth,bill_length <ResampleResult[21]>
#> 9: bill_depth,body_mass <ResampleResult[21]>
#> 10: bill_depth,flipper_length <ResampleResult[21]>
#> 11: bill_depth,island <ResampleResult[21]>
#> 12: bill_depth,sex <ResampleResult[21]>
#> 13: bill_depth,year <ResampleResult[21]>
#> 14: bill_length,body_mass <ResampleResult[21]>
#> 15: bill_length,flipper_length <ResampleResult[21]>
#> 16: bill_length,island <ResampleResult[21]>
#> 17: bill_length,sex <ResampleResult[21]>
#> 18: bill_length,year <ResampleResult[21]>
#> 19: body_mass,flipper_length <ResampleResult[21]>
#> 20: body_mass,island <ResampleResult[21]>
#> 21: body_mass,sex <ResampleResult[21]>
#> 22: body_mass,year <ResampleResult[21]>
#> 23: flipper_length,island <ResampleResult[21]>
#> 24: flipper_length,sex <ResampleResult[21]>
#> 25: flipper_length,year <ResampleResult[21]>
#> 26: island,sex <ResampleResult[21]>
#> 27: island,year <ResampleResult[21]>
#> 28: sex,year <ResampleResult[21]>
#> features resample_result
# subset the task and fit the final model
task$select(instance$result_feature_set)
learner$train(task)
# }