Table Of Contents

Previous topic

mvpa.clfs

Next topic

mvpa.clfs.blr

This Page

Quick search

mvpa.clfs.base

Base classes for all classifiers.

Base Classifiers can be grouped according to their function as

group Basic Classifiers:
 Classifier BoostedClassifier ProxyClassifier
group BoostedClassifiers:
 CombinedClassifier MulticlassClassifier SplitClassifier
group ProxyClassifiers:
 BinaryClassifier MappedClassifier FeatureSelectionClassifier
group PredictionsCombiners for CombinedClassifier:
 PredictionsCombiner MaximalVote MeanPrediction

The comprehensive API documentation for this module, including all technical details, is available in the Epydoc-generated API reference for mvpa.clfs.base (for developers).

Classes

BinaryClassifier

class mvpa.clfs.base.BinaryClassifier(clf, poslabels, neglabels, **kwargs)

Bases: mvpa.clfs.base.ProxyClassifier

ProxyClassifier which maps set of two labels into +1 and -1

Parameters:
  • clf (Classifier) – classifier to use
  • poslabels (list) – list of labels which are treated as +1 category
  • neglabels (list) – list of labels which are treated as -1 category

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the BinaryClassifier documentation.

Full API documentation of BinaryClassifier in module mvpa.clfs.base.

BoostedClassifier

class mvpa.clfs.base.BoostedClassifier(clfs=None, propagate_states=True, harvest_attribs=None, copy_attribs='copy', **kwargs)

Bases: mvpa.clfs.base.Classifier, mvpa.misc.state.Harvestable

Classifier containing the farm of other classifiers.

Should rarely be used directly. Use one of its childs instead

Initialize the instance.

Parameters:
  • clfs (list) – list of classifier instances to use (slave classifiers)
  • propagate_states (bool) – either to propagate enabled states into slave classifiers. It is in effect only when slaves get assigned - so if state is enabled not during construction, it would not necessarily propagate into slaves
  • harvest_attribs (list of basestr) – What attributes of call to store and return within harvested state variable
  • copy_attribs (None or basestr) – Force copying values of attributes on harvesting
  • kwargs (dict) – dict of keyworded arguments which might get used by State or Classifier
clfs
Used classifiers
getSensitivityAnalyzer(**kwargs)
Return an appropriate SensitivityAnalyzer
untrain()

Untrain BoostedClassifier

Has to untrain any known classifier

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the BoostedClassifier documentation.

Full API documentation of BoostedClassifier in module mvpa.clfs.base.

Classifier

class mvpa.clfs.base.Classifier(**kwargs)

Bases: mvpa.misc.state.ClassWithCollections

Abstract classifier class to be inherited by all classifiers

Cheap initialization.

getSensitivityAnalyzer(**kwargs)
Factory method to return an appropriate sensitivity analyzer for the respective classifier.
isTrained(dataset=None)

Either classifier was already trained.

MUST BE USED WITH CARE IF EVER

predict(data)

Predict classifier on data

Shouldn’t be overriden in subclasses unless explicitely needed to do so. Also subclasses trying to call super class’s predict should call _predict if within _predict instead of predict() since otherwise it would loop

repredict(data, **kwargs)

Helper to avoid check if data was changed actually changed

Useful if classifier was (re)trained but with the same data (so just parameters were changed), so that it could be repredicted easily (on the same data as before) without recomputing for instance train/test kernel matrix. Should be used with caution and always compared to the results on not ‘retrainable’ classifier. Some additional checks are enabled if debug id ‘CHECK_RETRAIN’ is enabled, to guard against obvious mistakes.

Parameters:
  • data – data which is conventionally given to predict
  • kwargs – that is what _changedData gets updated with. So, smth like (params=['C'], labels=True) if parameter C and labels got changed
retrain(dataset, **kwargs)

Helper to avoid check if data was changed actually changed

Useful if just some aspects of classifier were changed since its previous training. For instance if dataset wasn’t changed but only classifier parameters, then kernel matrix does not have to be computed.

Words of caution: classifier must be previousely trained, results always should first be compared to the results on not ‘retrainable’ classifier (without calling retrain). Some additional checks are enabled if debug id ‘CHECK_RETRAIN’ is enabled, to guard against obvious mistakes.

Parameters:
  • kwargs – that is what _changedData gets updated with. So, smth like (params=['C'], labels=True) if parameter C and labels got changed
summary()
Providing summary over the classifier
train(dataset)

Train classifier on a dataset

Shouldn’t be overriden in subclasses unless explicitely needed to do so

trained
Either classifier was already trained
untrain()
Reset trained state

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the Classifier documentation.

Full API documentation of Classifier in module mvpa.clfs.base.

ClassifierCombiner

class mvpa.clfs.base.ClassifierCombiner(clf, variables=None)

Bases: mvpa.clfs.base.PredictionsCombiner

Provides a decision using training a classifier on predictions/values

TODO

Initialize ClassifierCombiner

Parameters:
  • clf (Classifier) – Classifier to train on the predictions
  • variables (list of basestring) – List of state variables stored in ‘combined’ classifiers, which to use as features for training this classifier
untrain()
It might be needed to untrain used classifier

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the ClassifierCombiner documentation.

Full API documentation of ClassifierCombiner in module mvpa.clfs.base.

CombinedClassifier

class mvpa.clfs.base.CombinedClassifier(clfs=None, combiner=None, **kwargs)

Bases: mvpa.clfs.base.BoostedClassifier

BoostedClassifier which combines predictions using some PredictionsCombiner functor.

Initialize the instance.

Parameters:
  • clfs (list of Classifier) – list of classifier instances to use
  • combiner (PredictionsCombiner) – callable which takes care about combining multiple results into a single one (e.g. maximal vote for classification, MeanPrediction for regression))
  • kwargs (dict) – dict of keyworded arguments which might get used by State or Classifier
NB: combiner might need to operate not on ‘predictions’ descrete
labels but rather on raw ‘class’ values classifiers estimate (which is pretty much what is stored under values
combiner
Used combiner to derive a single result
summary()
untrain()
Untrain CombinedClassifier

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the CombinedClassifier documentation.

Full API documentation of CombinedClassifier in module mvpa.clfs.base.

FeatureSelectionClassifier

class mvpa.clfs.base.FeatureSelectionClassifier(clf, feature_selection, testdataset=None, **kwargs)

Bases: mvpa.clfs.base.ProxyClassifier

ProxyClassifier which uses some FeatureSelection prior training.

FeatureSelection is used first to select features for the classifier to use for prediction. Internally it would rely on MappedClassifier which would use created MaskMapper.

TODO: think about removing overhead of retraining the same classifier if feature selection was carried out with the same classifier already. It has been addressed by adding .trained property to classifier, but now we should expclitely use isTrained here if we want... need to think more

Initialize the instance

Parameters:
  • clf (Classifier) – classifier based on which mask classifiers is created
  • feature_selection (FeatureSelection) – whatever FeatureSelection comes handy
  • testdataset (Dataset) – optional dataset which would be given on call to feature_selection
feature_selection
Used FeatureSelection
getSensitivityAnalyzer(*args_, **kwargs_)
maskclf
Used MappedClassifier
setTestDataset(testdataset)
Set testing dataset to be used for feature selection
testdataset
untrain()

Untrain FeatureSelectionClassifier

Has to untrain any known classifier

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the FeatureSelectionClassifier documentation.

Full API documentation of FeatureSelectionClassifier in module mvpa.clfs.base.

MappedClassifier

class mvpa.clfs.base.MappedClassifier(clf, mapper, **kwargs)

Bases: mvpa.clfs.base.ProxyClassifier

ProxyClassifier which uses some mapper prior training/testing.

MaskMapper can be used just a subset of features to train/classify. Having such classifier we can easily create a set of classifiers for BoostedClassifier, where each classifier operates on some set of features, e.g. set of best spheres from SearchLight, set of ROIs selected elsewhere. It would be different from simply applying whole mask over the dataset, since here initial decision is made by each classifier and then later on they vote for the final decision across the set of classifiers.

Initialize the instance

Parameters:
  • clf (Classifier) – classifier based on which mask classifiers is created
  • mapper – whatever Mapper comes handy
getSensitivityAnalyzer(*args_, **kwargs_)
mapper
Used mapper

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the MappedClassifier documentation.

Full API documentation of MappedClassifier in module mvpa.clfs.base.

MaximalVote

class mvpa.clfs.base.MaximalVote

Bases: mvpa.clfs.base.PredictionsCombiner

Provides a decision using maximal vote rule

XXX Might get a parameter to use raw decision values if voting is not unambigous (ie two classes have equal number of votes

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the MaximalVote documentation.

Full API documentation of MaximalVote in module mvpa.clfs.base.

MeanPrediction

class mvpa.clfs.base.MeanPrediction(descr=None, **kwargs)

Bases: mvpa.clfs.base.PredictionsCombiner

Provides a decision by taking mean of the results

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the MeanPrediction documentation.

Full API documentation of MeanPrediction in module mvpa.clfs.base.

MulticlassClassifier

class mvpa.clfs.base.MulticlassClassifier(clf, bclf_type='1-vs-1', **kwargs)

Bases: mvpa.clfs.base.CombinedClassifier

CombinedClassifier to perform multiclass using a list of BinaryClassifier.

such as 1-vs-1 (ie in pairs like libsvm doesn) or 1-vs-all (which is yet to think about)

Initialize the instance

Parameters:
  • clf (Classifier) – classifier based on which multiple classifiers are created for multiclass
  • bclf_type – “1-vs-1” or “1-vs-all”, determines the way to generate binary classifiers

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the MulticlassClassifier documentation.

Full API documentation of MulticlassClassifier in module mvpa.clfs.base.

PredictionsCombiner

class mvpa.clfs.base.PredictionsCombiner(descr=None, **kwargs)

Bases: mvpa.misc.state.ClassWithCollections

Base class for combining decisions of multiple classifiers

train(clfs, dataset)

PredictionsCombiner might need to be trained

Parameters:
  • clfs (list of Classifier) – List of classifiers to combine. Has to be classifiers (not pure predictions), since combiner might use some other state variables (value’s) instead of pure prediction’s
  • dataset (Dataset) – training data in this case

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the PredictionsCombiner documentation.

Full API documentation of PredictionsCombiner in module mvpa.clfs.base.

ProxyClassifier

class mvpa.clfs.base.ProxyClassifier(clf, **kwargs)

Bases: mvpa.clfs.base.Classifier

Classifier which decorates another classifier

Possible uses:

  • modify data somehow prior training/testing: * normalization * feature selection * modification
  • optimized classifier?

Initialize the instance

Parameters:
  • clf (Classifier) – classifier based on which mask classifiers is created
clf
Used Classifier
getSensitivityAnalyzer(*args_, **kwargs_)
summary()
untrain()
Untrain ProxyClassifier

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the ProxyClassifier documentation.

Full API documentation of ProxyClassifier in module mvpa.clfs.base.

SplitClassifier

class mvpa.clfs.base.SplitClassifier(clf, splitter=<mvpa.datasets.splitter.NFoldSplitter object at 0x8cc072c>, **kwargs)

Bases: mvpa.clfs.base.CombinedClassifier

BoostedClassifier to work on splits of the data

Initialize the instance

Parameters:
  • clf (Classifier) – classifier based on which multiple classifiers are created for multiclass
  • splitter (Splitter) – Splitter to use to split the dataset prior training
getSensitivityAnalyzer(*args_, **kwargs_)
splitter
Splitter user by SplitClassifier

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the SplitClassifier documentation.

Full API documentation of SplitClassifier in module mvpa.clfs.base.