mvpa2.featsel.rfe.RFE

Inheritance diagram of RFE

class mvpa2.featsel.rfe.RFE(fmeasure, pmeasure, splitter, fselector=FractionTailSelector() fraction=0.050000, update_sensitivity=True, nfeatures_min=0, **kwargs)

Recursive feature elimination.

A FeaturewiseMeasure is used to compute sensitivity maps given a certain dataset. These sensitivity maps are in turn used to discard unimportant features. For each feature selection the transfer error on some testdatset is computed. This procedure is repeated until a given StoppingCriterion is reached.

Notes

Available conditional attributes:

  • calling_time+: None
  • errors+: History of errors
  • history+: Last step # when each feature was still present
  • nfeatures+: History of # of features left
  • raw_results: None
  • sensitivities: History of sensitivities (might consume too much memory
  • trained_dataset: None
  • trained_nsamples+: None
  • trained_targets+: None
  • training_time+: None

(Conditional attributes enabled by default suffixed with +)

References

Such strategy after
Guyon, I., Weston, J., Barnhill, S., & Vapnik, V. (2002). Gene selection for cancer classification using support vector machines. Mach. Learn., 46(1-3), 389–422.
was applied to SVM-based analysis of fMRI data in
Hanson, S. J. & Halchenko, Y. O. (2008). Brain reading using full brain support vector machines for object recognition: there is no “face identification area”. Neural Computation, 20, 486–503.

Examples

There are multiple possible ways to design an RFE. Here is one example which would rely on a SplitClassifier to extract sensitivities and provide estimate of performance (error)

>>> # Lazy import
>>> from mvpa2.suite import *
>>> rfesvm_split = SplitClassifier(LinearCSVMC(), OddEvenPartitioner())
>>> # design an RFE feature selection to be used with a classifier
>>> rfe = RFE(rfesvm_split.get_sensitivity_analyzer(
...              # take sensitivities per each split, L2 norm, mean, abs them
...              postproc=ChainMapper([ FxMapper('features', l2_normed),
...                                     FxMapper('samples', np.mean),
...                                     FxMapper('samples', np.abs)])),
...           # use the error stored in the confusion matrix of split classifier
...           ConfusionBasedError(rfesvm_split, confusion_state='stats'),
...           # we just extract error from confusion, so need to split dataset
...           Repeater(2),
...           # select 50% of the best on each step
...           fselector=FractionTailSelector(
...               0.50,
...               mode='select', tail='upper'),
...           # and stop whenever error didn't improve for up to 10 steps
...           stopping_criterion=NBackHistoryStopCrit(BestDetector(), 10),
...           # we just extract it from existing confusion
...           train_pmeasure=False,
...           # but we do want to update sensitivities on each step
...           update_sensitivity=True)
>>> clf = FeatureSelectionClassifier(
...           LinearCSVMC(),
...           # on features selected via RFE
...           rfe,
...           # custom description
...           descr='LinSVM+RFE(splits_avg)' )

Note: If you rely on cross-validation for the StoppingCriterion, make sure that you have at least 3 chunks so that SplitClassifier could have at least 2 chunks to split. Otherwise it can not split more (one chunk could not be splitted).

Methods

Initialize recursive feature elimination

Parameters:

fmeasure : FeaturewiseMeasure

pmeasure : Measure

used to compute the transfer error of a classifier based on a certain feature set on the test dataset. NOTE: If sensitivity analyzer is based on the same classifier as transfer_error is using, make sure you initialize transfer_error with train=False, otherwise it would train classifier twice without any necessity.

splitter: Splitter :

This splitter instance has to generate at least two dataset splits when called with the input dataset. The first split serves as the training dataset and the second as the evaluation dataset.

fselector : Functor

Given a sensitivity map it has to return the ids of those features that should be kept.

update_sensitivity : bool

If False the sensitivity map is only computed once and reused for each iteration. Otherwise the senstitivities are recomputed at each selection step.

nfeatures_min : int

Number of features for RFE to stop if reached.

enable_ca : None or list of str

Names of the conditional attributes which should be enabled in addition to the default ones

disable_ca : None or list of str

Names of the conditional attributes which should be disabled

bestdetector : Functor

Given a list of error values it has to return a boolean that signals whether the latest error value is the total minimum.

stopping_criterion : Functor

Given a list of error values it has to return whether the criterion is fulfilled.

train_pmeasure : bool

Flag whether the pmeasure should be trained before computing the error. In general this is required, but if the fmeasure and pmeasure share and make use of the same classifier AND pmeasure does not really need training, it can be switched off to save CPU cycles.

filler : optional

Value to fill empty entries upon reverse operation

auto_train : bool

Flag whether the learner will automatically train itself on the input dataset when called untrained.

force_train : bool

Flag whether the learner will enforce training on the input dataset upon every call.

space : str, optional

Name of the ‘processing space’. The actual meaning of this argument heavily depends on the sub-class implementation. In general, this is a trigger that tells the node to compute and store information about the input data that is “interesting” in the context of the corresponding processing in the output dataset.

pass_attr : str, list of str|tuple, optional

Additional attributes to pass on to an output dataset. Attributes can be taken from all three attribute collections of an input dataset (sa, fa, a – see Dataset.get_attr()), or from the collection of conditional attributes (ca) of a node instance. Corresponding collection name prefixes should be used to identify attributes, e.g. ‘ca.null_prob’ for the conditional attribute ‘null_prob’, or ‘fa.stats’ for the feature attribute stats. In addition to a plain attribute identifier it is possible to use a tuple to trigger more complex operations. The first tuple element is the attribute identifier, as described before. The second element is the name of the target attribute collection (sa, fa, or a). The third element is the axis number of a multidimensional array that shall be swapped with the current first axis. The fourth element is a new name that shall be used for an attribute in the output dataset. Example: (‘ca.null_prob’, ‘fa’, 1, ‘pvalues’) will take the conditional attribute ‘null_prob’ and store it as a feature attribute ‘pvalues’, while swapping the first and second axes. Simplified instructions can be given by leaving out consecutive tuple elements starting from the end.

postproc : Node instance, optional

Node to perform post-processing of results. This node is applied in __call__() to perform a final processing step on the to be result dataset. If None, nothing is done.

descr : str

Description of the instance

Methods

nfeatures_min
update_sensitivity