
Feature Selection with Random Search
Source:R/FSelectorRandomSearch.R
mlr_fselectors_random_search.Rd
Feature selection using Random Search Algorithm.
Source
Bergstra J, Bengio Y (2012). “Random Search for Hyper-Parameter Optimization.” Journal of Machine Learning Research, 13(10), 281--305. https://jmlr.csail.mit.edu/papers/v13/bergstra12a.html.
Details
The feature sets are randomly drawn.
The sets are evaluated in batches of size batch_size
.
Larger batches mean we can parallelize more, smaller batches imply a more fine-grained checking of termination criteria.
Dictionary
This FSelector can be instantiated with the associated sugar function fs()
:
fs("random_search")
Control Parameters
max_features
integer(1)
Maximum number of features. By default, number of features in mlr3::Task.batch_size
integer(1)
Maximum number of feature sets to try in a batch.
Super class
mlr3fselect::FSelector
-> FSelectorRandomSearch
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("random_search"),
task = task,
learner = learner,
resampling = rsmp("holdout"),
measure = msr("classif.ce"),
term_evals = 10
)
# best performing feature subset
instance$result
#> bill_depth bill_length body_mass flipper_length island sex year
#> 1: TRUE TRUE TRUE TRUE TRUE FALSE FALSE
#> features classif.ce
#> 1: bill_depth,bill_length,body_mass,flipper_length,island 0.06086957
# all evaluated feature subsets
as.data.table(instance$archive)
#> bill_depth bill_length body_mass flipper_length island sex year
#> 1: TRUE TRUE TRUE TRUE TRUE FALSE FALSE
#> 2: TRUE TRUE TRUE FALSE TRUE TRUE TRUE
#> 3: FALSE TRUE TRUE TRUE TRUE TRUE TRUE
#> 4: FALSE FALSE TRUE TRUE TRUE TRUE TRUE
#> 5: TRUE FALSE FALSE TRUE FALSE FALSE TRUE
#> 6: TRUE TRUE TRUE FALSE TRUE TRUE FALSE
#> 7: TRUE TRUE TRUE TRUE TRUE FALSE TRUE
#> 8: FALSE TRUE TRUE TRUE TRUE FALSE FALSE
#> 9: TRUE TRUE TRUE FALSE FALSE TRUE TRUE
#> 10: TRUE FALSE FALSE TRUE TRUE FALSE TRUE
#> classif.ce runtime_learners timestamp batch_nr warnings errors
#> 1: 0.06086957 0.009 2023-03-02 12:42:36 1 0 0
#> 2: 0.09565217 0.009 2023-03-02 12:42:36 2 0 0
#> 3: 0.06086957 0.009 2023-03-02 12:42:36 3 0 0
#> 4: 0.17391304 0.010 2023-03-02 12:42:36 4 0 0
#> 5: 0.20000000 0.009 2023-03-02 12:42:36 5 0 0
#> 6: 0.09565217 0.009 2023-03-02 12:42:36 6 0 0
#> 7: 0.06086957 0.012 2023-03-02 12:42:36 7 0 0
#> 8: 0.06086957 0.009 2023-03-02 12:42:36 8 0 0
#> 9: 0.13043478 0.008 2023-03-02 12:42:36 9 0 0
#> 10: 0.17391304 0.008 2023-03-02 12:42:36 10 0 0
#> features
#> 1: bill_depth,bill_length,body_mass,flipper_length,island
#> 2: bill_depth,bill_length,body_mass,island,sex,year
#> 3: bill_length,body_mass,flipper_length,island,sex,year
#> 4: body_mass,flipper_length,island,sex,year
#> 5: bill_depth,flipper_length,year
#> 6: bill_depth,bill_length,body_mass,island,sex
#> 7: bill_depth,bill_length,body_mass,flipper_length,island,year
#> 8: bill_length,body_mass,flipper_length,island
#> 9: bill_depth,bill_length,body_mass,sex,year
#> 10: bill_depth,flipper_length,island,year
#> resample_result
#> 1: <ResampleResult[21]>
#> 2: <ResampleResult[21]>
#> 3: <ResampleResult[21]>
#> 4: <ResampleResult[21]>
#> 5: <ResampleResult[21]>
#> 6: <ResampleResult[21]>
#> 7: <ResampleResult[21]>
#> 8: <ResampleResult[21]>
#> 9: <ResampleResult[21]>
#> 10: <ResampleResult[21]>
# subset the task and fit the final model
task$select(instance$result_feature_set)
learner$train(task)
# }