Learn R Programming

mlr3fselect (version 0.2.1)

AutoFSelect: AutoFSelect

Description

The AutoFSelect is a mlr3::Learner which wraps another mlr3::Learner and performs the following steps during $train():

  1. The wrapped (inner) learner is trained on the feature subsets via resampling. The feature selection can be specified by providing a FSelector, a bbotk::Terminator, a mlr3::Resampling and a mlr3::Measure.

  2. A final model is fit on the complete training data with the best found feature subset.

During $predict() the AutoFSelect just calls the predict method of the wrapped (inner) learner.

Note that this approach allows to perform nested resampling by passing an AutoFSelect object to mlr3::resample() or mlr3::benchmark(). To access the inner resampling results, set store_fselect_instance = TRUE and execute mlr3::resample() or mlr3::benchmark() with store_models = TRUE (see examples).

Arguments

Super class

mlr3::Learner -> AutoFSelect

Public fields

instance_args

(list()) All arguments from construction to create the FSelectInstanceSingleCrit.

fselector

(FSelector) Stores the feature selection algorithm.

store_fselect_instance

(logical(1)). If TRUE (default), stores the internally created FSelectInstanceSingleCrit with all intermediate results in slot $fselect_instance.

Active bindings

archive

(bbotk::Archive) Returns FSelectInstanceSingleCrit archive.

learner

(mlr3::Learner) Trained learner.

fselect_instance

(FSelectInstanceSingleCrit) Internally created feature selection instance with all intermediate results.

fselect_result

(named list()) Short-cut to $result from FSelectInstanceSingleCrit.

Methods

Public methods

Method new()

Creates a new instance of this R6 class.

Usage

AutoFSelect$new(learner, resampling, measure, terminator, fselector)

Arguments

learner

(mlr3::Learner) Learner to optimize the feature subset for, see FSelectInstanceSingleCrit.

resampling

(mlr3::Resampling) Resampling strategy during feature selection, see FSelectInstanceSingleCrit. This mlr3::Resampling is meant to be the inner resampling, operating on the training set of an arbitrary outer resampling. For this reason it is not feasible to pass an instantiated mlr3::Resampling here.

measure

(mlr3::Measure) Performance measure to optimize.

terminator

(bbotk::Terminator) When to stop feature selection, see FSelectInstanceSingleCrit.

fselector

(FSelector) Feature selection algorithm to run.

Method clone()

The objects of this class are cloneable with this method.

Usage

AutoFSelect$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

Run this code
# NOT RUN {
library(mlr3)

task = tsk("iris")
learner = lrn("classif.rpart")
resampling = rsmp("holdout")
measure = msr("classif.ce")

terminator = trm("evals", n_evals = 15)
fselector = fs("exhaustive_search")
afs = AutoFSelect$new(learner, resampling, measure, terminator, fselector)
afs$store_fselect_instance = TRUE

afs$train(task)
afs$model
afs$learner

#  Nested resampling
afs = AutoFSelect$new(learner, resampling, measure, terminator, fselector)
afs$store_fselect_instance = TRUE

resampling_outer = rsmp("cv", folds = 2)
rr = resample(task, afs, resampling_outer, store_models = TRUE)

# Aggregate performance of outer results
rr$aggregate()

# Retrieve inner feature selection results.
as.data.table(rr)$learner[[1]]$fselect_result
# }

Run the code above in your browser using DataLab