Table Of Contents

Previous topic

mappers.zscore

Next topic

clfs.blr

This content refers to the previous stable release of PyMVPA. Please visit www.pymvpa.org for the most recent version of PyMVPA and its documentation.

clfs.base

Module: clfs.base

Inheritance diagram for mvpa.clfs.base:

Base class for all classifiers.

At the moment, regressions are treated just as a special case of classifier (or vise verse), so the same base class Classifier is utilized for both kinds.

Classes

Classifier

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

Bases: mvpa.misc.state.ClassWithCollections

Abstract classifier class to be inherited by all classifiers

Note

Available state variables:

  • feature_ids: Feature IDS which were used for the actual training.
  • predicting_time+: Time (in seconds) which took classifier to predict
  • predictions+: Most recent set of predictions
  • trained_dataset: The dataset it has been trained on
  • trained_labels+: Set of unique labels it has been trained on
  • trained_nsamples+: Number of samples it has been trained on
  • training_confusion: Confusion matrix of learning performance
  • training_time+: Time (in seconds) which took classifier to train
  • values+: Internal classifier values the most recent predictions are based on

(States enabled by default are listed with +)

See also

Please refer to the documentation of the base class for more information:

ClassWithCollections

Cheap initialization.

Parameters:
  • enable_states (None or list of basestring) – Names of the state variables which should be enabled additionally to default ones
  • disable_states (None or list of basestring) – Names of the state variables which should be disabled
clone()

Create full copy of the classifier.

It might require classifier to be untrained first due to present SWIG bindings.

TODO: think about proper re-implementation, without enrollment of deepcopy

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 overridden in subclasses unless explicitly 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 previously 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 overridden in subclasses unless explicitly needed to do so

trained

Either classifier was already trained

untrain()

Reset trained state

DegenerateInputError

class mvpa.clfs.base.DegenerateInputError

Bases: mvpa.clfs.base.LearnerError

Exception to be thrown by learners if input data is bogus, i.e. no features or samples

FailedToPredictError

class mvpa.clfs.base.FailedToPredictError

Bases: mvpa.clfs.base.LearnerError

Exception to be thrown whenever classifier fails to provide predictions. Usually happens if it was trained on degenerate data but without any complaints.

FailedToTrainError

class mvpa.clfs.base.FailedToTrainError

Bases: mvpa.clfs.base.LearnerError

Exception to be thrown whenever classifier fails to learn for some reason

LearnerError

class mvpa.clfs.base.LearnerError

Bases: exceptions.Exception

Base class for exceptions thrown by the learners (classifiers, regressions)