Skip to contents

Filter using embedded feature selection of machine learning algorithms. Takes a mlr3::Learner which is capable of extracting the selected features (property "selected_features"), fits the model and extracts the selected features.

Note that contrary to mlr_filters_importance, there is no ordering in the selected features. Selected features get a score of 1, deselected features get a score of 0. The order of selected features is random and different from the order in the learner. In combination with mlr3pipelines, only the filter criterion cutoff makes sense.

Super classes

mlr3filters::Filter -> mlr3filters::FilterLearner -> FilterSelectedFeatures

Public fields

learner

(mlr3::Learner)
Learner to extract the importance values from.

Methods

Inherited methods


Method new()

Create a FilterImportance object.

Usage

FilterSelectedFeatures$new(learner = mlr3::lrn("classif.featureless"))

Arguments

learner

(mlr3::Learner)
Learner to extract the selected features from.


Method clone()

The objects of this class are cloneable with this method.

Usage

FilterSelectedFeatures$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (requireNamespace("rpart")) {
  task = mlr3::tsk("iris")
  learner = mlr3::lrn("classif.rpart")
  filter = flt("selected_features", learner = learner)
  filter$calculate(task)
  as.data.table(filter)
}
#>         feature score
#>          <char> <num>
#> 1:  Petal.Width     1
#> 2: Petal.Length     1
#> 3:  Sepal.Width     0
#> 4: Sepal.Length     0

if (mlr3misc::require_namespaces(c("mlr3pipelines", "mlr3learners", "rpart"), quietly = TRUE)) {
  library("mlr3pipelines")
  library("mlr3learners")
  task = mlr3::tsk("sonar")

  filter = flt("selected_features", learner = lrn("classif.rpart"))

  # Note: All filter scores are either 0 or 1, i.e. setting `filter.cutoff = 0.5` means that
  # we select all "selected features".

  graph = po("filter", filter = filter, filter.cutoff = 0.5) %>>%
    po("learner", mlr3::lrn("classif.log_reg"))

  graph$train(task)
}
#> $classif.log_reg.output
#> NULL
#>