mlr_fselectors_rfecv {mlr3fselect} | R Documentation |
Feature Selection with Recursive Feature Elimination with Cross Validation
Description
Feature selection using the Recursive Feature Elimination with Cross-Validation (RFE-CV) algorithm. See FSelectorBatchRFE for a description of the base algorithm. RFE-CV runs a recursive feature elimination in each iteration of a cross-validation to determine the optimal number of features. Then a recursive feature elimination is run again on the complete dataset with the optimal number of features as the final feature set size. The performance of the optimal feature set is calculated on the complete data set and should not be reported as the performance of the final model. Only works with mlr3::Learners that can calculate importance scores (see the section on optional extractors in mlr3::Learner).
Details
The resampling strategy is changed during the feature selection.
The resampling strategy passed to the instance (resampling
) is used to determine the optimal number of features.
Usually, a cross-validation strategy is used and a recursive feature elimination is run in each iteration of the cross-validation.
Internally, mlr3::ResamplingCustom is used to emulate this part of the algorithm.
In the final recursive feature elimination run the resampling strategy is changed to mlr3::ResamplingInsample i.e. the complete data set is used for training and testing.
The feature selection terminates itself when the optimal number of features is reached. It is not necessary to set a termination criterion.
Archive
The ArchiveBatchFSelect holds the following additional columns:
-
"iteration"
(integer(1)
)
The resampling iteration in which the feature subset was evaluated. -
"importance"
(numeric()
)
The importance score vector of the feature subset.
Resources
The gallery features a collection of case studies and demos about optimization.
Utilize the built-in feature importance of models with Recursive Feature Elimination.
Dictionary
This FSelector can be instantiated with the associated sugar function fs()
:
fs("rfe")
Control Parameters
n_features
integer(1)
The number of features to select. By default half of the features are selected.feature_fraction
double(1)
Fraction of features to retain in each iteration. The default 0.5 retrains half of the features.feature_number
integer(1)
Number of features to remove in each iteration.subset_sizes
integer()
Vector of number of features to retain in each iteration. Must be sorted in decreasing order.recursive
logical(1)
IfTRUE
(default), the feature importance is calculated in each iteration.
The parameter feature_fraction
, feature_number
and subset_sizes
are mutually exclusive.
Super classes
mlr3fselect::FSelector
-> mlr3fselect::FSelectorBatch
-> FSelectorBatchRFECV
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of this R6 class.
Usage
FSelectorBatchRFECV$new()
Method clone()
The objects of this class are cloneable with this method.
Usage
FSelectorBatchRFECV$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Other FSelector:
FSelector
,
mlr_fselectors
,
mlr_fselectors_design_points
,
mlr_fselectors_exhaustive_search
,
mlr_fselectors_genetic_search
,
mlr_fselectors_random_search
,
mlr_fselectors_rfe
,
mlr_fselectors_sequential
,
mlr_fselectors_shadow_variable_search
Examples
# Feature Selection
# 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("rfecv"),
task = task,
learner = learner,
resampling = rsmp("cv", folds = 3),
measure = msr("classif.ce"),
store_models = TRUE
)
# best performing feature subset
instance$result
# all evaluated feature subsets
as.data.table(instance$archive)
# subset the task and fit the final model
task$select(instance$result_feature_set)
learner$train(task)