Learn R Programming

mlr (version 1.1-18)

selectFeatures: Feature selection by wrapper approach.

Description

Optimizes the features for a classification or regression problem by choosing a variable selection wrapper approach. Allows for different optimization methods, such as forward search or a genetic algorithm. You can select such an algorithm (and its settings) by passing a corresponding control object. For a complete list of implemented algorithms look at the subclasses of [FeatSelControl].

Usage

selectFeatures(learner, task, resampling, control,
    measures, bit.names, bits.to.features,
    show.info = TRUE)

Arguments

Value

[FeatSelResult].

Details

All algorithms operate on a 0-1-bit encoding of candidate solutions. Per default a single bit corresponds to a single feature, but you are able to change this by using the arguments bit.names and bits.to.features. Thus allowing you to switch on whole groups of features with a single bit.

Examples

Run this code
task <- makeClassifTask(data=iris, target="Species")
lrn <- makeLearner("classif.rpart")
rdesc <- makeResampleDesc("Holdout")

## Now create control-objects for each of the possible feature selection algorithms:
ctrlSeq <- makeFeatSelControlSequential(method="sfs", maxit=NA)
ctrlGA <- makeFeatSelControlGA(maxit=5, max.features=NA, crossover.rate=0.5,
  mutation.rate=0.1, mu=10, lambda=5)
ctrlRand <- makeFeatSelControlRandom(maxit=10, max.features=NA, prob=0.5)
ctrlExh <- makeFeatSelControlExhaustive(maxit=NA, max.features=NA)

## Let's run the feature selction algorithm:

sfSeq <- selectFeatures(lrn, task, rdesc, control=ctrlSeq)
sfSeq
sfGA <- selectFeatures(lrn, task, rdesc, control=ctrlGA)
sfGA
sfRand <- selectFeatures(lrn, task, rdesc, control=ctrlRand)
sfRand
sfExh <- selectFeatures(lrn, task, rdesc, control=ctrlExh)
sfExh

Run the code above in your browser using DataLab