Multivariate Pattern Analysis in Python

### Navigation

- index
- modules |
- modules |
- PyMVPA Home |
- Sitemap »

# mvpa2.featsel.rfe.RFE

class `mvpa2.featsel.rfe.``RFE`(fmeasure, pmeasure, splitter, fselector=FractionTailSelector() fraction=0.050000, update_sensitivity=True, **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+`: Time (in seconds) it took to call the node
  - `errors+`: History of errors
  - `history+`: Last step # when each feature was still present
  - `nfeatures+`: History of # of features left
  - `raw_results`: Computed results before invoking postproc. Stored only if postproc is not None.
  - `sensitivities`: History of sensitivities (might consume too much memory
  - `training_time+`: Time (in seconds) it took to train the learner

  (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)' )

  Methods

  `forward`(data) | Map data from input to output space.
  `forward1`(data) | Wrapper method to map single samples.
  `generate`(ds) | Yield processing results.
  `get_postproc`() | Returns the post-processing node or None.
  `get_space`() | Query the processing space name of this node.
  `reset`() |
  `reverse`(data) | Reverse-map data from output back into input space.
  `reverse1`(data) |
  `set_postproc`(node) | Assigns a post-processing node Set to `None` to disable postprocessing.
  `set_space`(name) | Set the processing space name of this node.
  `train`(ds) | The default implementation calls `_pretrain()`, `_train()`, and finally `_posttrain()`.
  `untrain`() | Reverts changes in the state of this node caused by previous training

  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.

  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_clf : bool

  > Flag whether the classifier in `transfer_error` should be trained before computing the error. In general this is required, but if the `sensitivity_analyzer` and `transfer_error` share and make use of the same classifier it can be switched off to save CPU cycles. Default `None` checks if sensitivity_analyzer is based on a classifier and doesn’t train if so.

  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.

  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

  `forward`(data) | Map data from input to output space.
  `forward1`(data) | Wrapper method to map single samples.
  `generate`(ds) | Yield processing results.
  `get_postproc`() | Returns the post-processing node or None.
  `get_space`() | Query the processing space name of this node.
  `reset`() |
  `reverse`(data) | Reverse-map data from output back into input space.
  `reverse1`(data) |
  `set_postproc`(node) | Assigns a post-processing node Set to `None` to disable postprocessing.
  `set_space`(name) | Set the processing space name of this node.
  `train`(ds) | The default implementation calls `_pretrain()`, `_train()`, and finally `_posttrain()`.
  `untrain`() | Reverts changes in the state of this node caused by previous training

### Navigation

- index
- modules |
- modules |
- PyMVPA Home |
- Sitemap »