MyNixOS website logo
Description

Filter Based Feature Selection for 'mlr3'.

Extends 'mlr3' with filter methods for feature selection. Besides standalone filter methods built-in methods of any machine-learning algorithm are supported. Partial scoring of multivariate filter methods is supported.

mlr3filters

Package website: release | dev

{mlr3filters} adds feature selection filters to mlr3. The implemented filters can be used stand-alone, or as part of a machine learning pipeline in combination with mlr3pipelines and the filter operator.

Wrapper methods for feature selection are implemented in mlr3fselect. Learners which support the extraction feature importance scores can be combined with a filter from this package for embedded feature selection.

r-cmd-check CRANStatus StackOverflow Mattermost

Installation

CRAN version

install.packages("mlr3filters")

Development version

remotes::install_github("mlr-org/mlr3filters")

Filters

Filter Example

set.seed(1)
library("mlr3")
library("mlr3filters")

task = tsk("sonar")
filter = flt("auc")
head(as.data.table(filter$calculate(task)))
##    feature     score
## 1:     V11 0.2811368
## 2:     V12 0.2429182
## 3:     V10 0.2327018
## 4:     V49 0.2312622
## 5:      V9 0.2308442
## 6:     V48 0.2062784

Implemented Filters

NamelabelTask TypesFeature TypesPackage
anovaANOVA F-TestClassifInteger, Numericstats
aucArea Under the ROC Curve ScoreClassifInteger, Numericmlr3measures
carscoreCorrelation-Adjusted coRrelation ScoreRegrLogical, Integer, Numericcare
carsurvscoreCorrelation-Adjusted coRrelation Survival ScoreSurvInteger, NumericcarSurv, mlr3proba
cmimMinimal Conditional Mutual Information MaximizationClassif & RegrInteger, Numeric, Factor, Orderedpraznik
correlationCorrelationRegrInteger, Numericstats
disrDouble Input Symmetrical RelevanceClassif & RegrInteger, Numeric, Factor, Orderedpraznik
find_correlationCorrelation-based ScoreUniversalInteger, Numericstats
importanceImportance ScoreUniversalLogical, Integer, Numeric, Character, Factor, Ordered, POSIXct
information_gainInformation GainClassif & RegrInteger, Numeric, Factor, OrderedFSelectorRcpp
jmiJoint Mutual InformationClassif & RegrInteger, Numeric, Factor, Orderedpraznik
jmimMinimal Joint Mutual Information MaximizationClassif & RegrInteger, Numeric, Factor, Orderedpraznik
kruskal_testKruskal-Wallis TestClassifInteger, Numericstats
mimMutual Information MaximizationClassif & RegrInteger, Numeric, Factor, Orderedpraznik
mrmrMinimum Redundancy Maximal RelevancyClassif & RegrInteger, Numeric, Factor, Orderedpraznik
njmimMinimal Normalised Joint Mutual Information MaximizationClassif & RegrInteger, Numeric, Factor, Orderedpraznik
performancePredictive PerformanceUniversalLogical, Integer, Numeric, Character, Factor, Ordered, POSIXct
permutationPermutation ScoreUniversalLogical, Integer, Numeric, Character, Factor, Ordered, POSIXct
reliefRELIEFClassif & RegrInteger, Numeric, Factor, OrderedFSelectorRcpp
selected_featuresEmbedded Feature SelectionUniversalLogical, Integer, Numeric, Character, Factor, Ordered, POSIXct
univariate_coxUnivariate Cox Survival ScoreSurvInteger, Numeric, Logicalsurvival
varianceVarianceUniversalInteger, Numericstats

Variable Importance Filters

The following learners allow the extraction of variable importance and therefore are supported by FilterImportance:

## [1] "classif.featureless" "classif.ranger"      "classif.rpart"      
## [4] "classif.xgboost"     "regr.featureless"    "regr.ranger"        
## [7] "regr.rpart"          "regr.xgboost"

If your learner is not listed here but capable of extracting variable importance from the fitted model, the reason is most likely that it is not yet integrated in the package mlr3learners or the extra learner extension. Please open an issue so we can add your package.

Some learners need to have their variable importance measure “activated” during learner creation. For example, to use the “impurity” measure of Random Forest via the {ranger} package:

task = tsk("iris")
lrn = lrn("classif.ranger", seed = 42)
lrn$param_set$values = list(importance = "impurity")

filter = flt("importance", learner = lrn)
filter$calculate(task)
head(as.data.table(filter), 3)
##         feature     score
## 1: Petal.Length 44.682462
## 2:  Petal.Width 43.113031
## 3: Sepal.Length  9.039099

Performance Filter

FilterPerformance is a univariate filter method which calls resample() with every predictor variable in the dataset and ranks the final outcome using the supplied measure. Any learner can be passed to this filter with classif.rpart being the default. Of course, also regression learners can be passed if the task is of type “regr”.

Filter-based Feature Selection

In many cases filtering is only one step in the modeling pipeline. To select features based on filter values, one can use PipeOpFilter from mlr3pipelines.

library(mlr3pipelines)
task = tsk("spam")

# the `filter.frac` should be tuned
graph = po("filter", filter = flt("auc"), filter.frac = 0.5) %>>%
  po("learner", lrn("classif.rpart"))

learner = as_learner(graph)
rr = resample(task, learner, rsmp("holdout"))
Metadata

Version

0.8.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows