Learn R Programming

flacco (version 1.1)

plotFeatureImportance: Feature Importance Plot

Description

Creates a feature importance plot.

Usage

plotFeatureImportance(featureList, control = list(), ...)

Arguments

featureList
[list] List of vectors of features. One list element is expected to belong to one resampling iteration / fold.
control
[list] A list, which stores additional configuration parameters:
  • featimp.col_{high/medium/low}
: Color of the features, which are used often, sometimes or only a few times. featimp.perc_{high/low}

Value

  • [plot]. Feature Importance Plot, indicating which feature was used during which iteration.

item

...

cr

Further arguments, which can be passed to plot.

Examples

Run this code
# At the beginning, one needs a list of features, e.g. derived during a
# nested feature selection within mlr (see the following 8 steps):
library(mlr)
library(mlbench)
data(Glass)

# (1) Create a classification task:
classifTask = makeClassifTask(data = Glass, target = "Type")

# (2) Define the model (here, a classification tree):
lrn = makeLearner(cl = "classif.rpart")

# (3) Define the resampling strategy, which is supposed to be used within 
# each inner loop of the nested feature selection:
innerResampling = makeResampleDesc("Holdout")

# (4) What kind of feature selection approach should be used? Here, we use a
# sequential backward strategy, i.e. starting from a model with all features,
# in each step the feature decreasing the performance measure the least is
# removed from the model:
ctrl = makeFeatSelControlSequential(method = "sbs")

# (5) Wrap the original model (see (2)) in order to allow feature selection:
wrappedLearner = makeFeatSelWrapper(learner = lrn,
  resampling = innerResampling, control = ctrl)

# (6) Define a resampling strategy for the outer loop. This is necessary in
# order to assess whether the selected features depend on the underlying
# fold:
outerResampling = makeResampleDesc(method = "CV", iters = 10L)

# (7) Perform the feature selection:
featselResult = resample(learner = wrappedLearner, task = classifTask,
  resampling = outerResampling, models = TRUE)

# (8) Extract the features, which were selected during each iteration of the
# outer loop (i.e. during each of the 5 folds of the cross-validation):
featureList = lapply(featselResult$models, 
  function(mod) getFeatSelResult(mod)$x)

########################################################################

# Now, one could inspect the features manually:
featureList

# Alternatively, one might use visual means such as the feature
# importance plot:
plotFeatureImportance(featureList)

Run the code above in your browser using DataLab