Skip to contents

Feature selection using the Genetic Algorithm from the package genalg.

Dictionary

This FSelector can be instantiated with the associated sugar function fs():

fs("genetic_search")

Control Parameters

For the meaning of the control parameters, see genalg::rbga.bin(). genalg::rbga.bin() internally terminates after iters iteration. We set ìters = 100000 to allow the termination via our terminators. If more iterations are needed, set ìters to a higher value in the parameter set.

Super class

mlr3fselect::FSelector -> FSelectorGeneticSearch

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.


Method clone()

The objects of this class are cloneable with this method.

Usage

FSelectorGeneticSearch$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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("genetic_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:       TRUE        TRUE     FALSE          FALSE  FALSE FALSE FALSE
#>                  features classif.ce
#> 1: bill_depth,bill_length 0.09565217

# all evaluated feature sets
as.data.table(instance$archive)
#>     bill_depth bill_length body_mass flipper_length island   sex  year
#>  1:      FALSE       FALSE     FALSE           TRUE  FALSE FALSE FALSE
#>  2:      FALSE       FALSE     FALSE           TRUE  FALSE FALSE FALSE
#>  3:      FALSE       FALSE     FALSE          FALSE  FALSE FALSE  TRUE
#>  4:      FALSE       FALSE     FALSE          FALSE   TRUE FALSE FALSE
#>  5:      FALSE       FALSE      TRUE          FALSE  FALSE FALSE FALSE
#>  6:       TRUE        TRUE     FALSE          FALSE  FALSE FALSE FALSE
#>  7:      FALSE        TRUE     FALSE          FALSE  FALSE FALSE FALSE
#>  8:      FALSE       FALSE     FALSE          FALSE  FALSE FALSE  TRUE
#>  9:      FALSE       FALSE      TRUE           TRUE   TRUE  TRUE FALSE
#> 10:      FALSE       FALSE     FALSE           TRUE  FALSE FALSE FALSE
#>     classif.ce runtime_learners           timestamp batch_nr warnings errors
#>  1: 0.24347826            0.009 2023-03-02 12:42:34        1        0      0
#>  2: 0.24347826            0.008 2023-03-02 12:42:34        2        0      0
#>  3: 0.58260870            0.008 2023-03-02 12:42:34        3        0      0
#>  4: 0.33913043            0.008 2023-03-02 12:42:34        4        0      0
#>  5: 0.33913043            0.009 2023-03-02 12:42:34        5        0      0
#>  6: 0.09565217            0.008 2023-03-02 12:42:34        6        0      0
#>  7: 0.31304348            0.012 2023-03-02 12:42:34        7        0      0
#>  8: 0.58260870            0.007 2023-03-02 12:42:34        8        0      0
#>  9: 0.13913043            0.009 2023-03-02 12:42:34        9        0      0
#> 10: 0.24347826            0.007 2023-03-02 12:42:34       10        0      0
#>                                features      resample_result
#>  1:                      flipper_length <ResampleResult[21]>
#>  2:                      flipper_length <ResampleResult[21]>
#>  3:                                year <ResampleResult[21]>
#>  4:                              island <ResampleResult[21]>
#>  5:                           body_mass <ResampleResult[21]>
#>  6:              bill_depth,bill_length <ResampleResult[21]>
#>  7:                         bill_length <ResampleResult[21]>
#>  8:                                year <ResampleResult[21]>
#>  9: body_mass,flipper_length,island,sex <ResampleResult[21]>
#> 10:                      flipper_length <ResampleResult[21]>

# subset the task and fit the final model
task$select(instance$result_feature_set)
learner$train(task)
# }