Skip to contents

Variable Importance filter using embedded feature selection of machine learning algorithms. Takes a mlr3::Learner which is capable of extracting the variable importance (property "importance"), fits the model and extracts the importance values to use as filter scores.

Super classes

mlr3filters::Filter -> mlr3filters::FilterLearner -> FilterImportance

Public fields

learner

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

Methods

Inherited methods


Method new()

Create a FilterImportance object.

Usage

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

Arguments

learner

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


Method clone()

The objects of this class are cloneable with this method.

Usage

FilterImportance$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("importance", learner = learner)
  filter$calculate(task)
  as.data.table(filter)
}
#>         feature    score
#>          <char>    <num>
#> 1:  Petal.Width 88.96940
#> 2: Petal.Length 81.34496
#> 3: Sepal.Length 54.09606
#> 4:  Sepal.Width 36.01309

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

  learner = mlr3::lrn("classif.rpart")

  # Note: `filter.frac` is selected randomly and should be tuned.

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

  graph$train(task)
}
#> Loading required package: mlr3
#> $classif.log_reg.output
#> NULL
#>