Package mvpa :: Package clfs :: Module base :: Class Classifier
[hide private]
[frames] | no frames]

Class Classifier

source code


Abstract classifier class to be inherited by all classifiers
Nested Classes [hide private]

Inherited from misc.state.ClassWithCollections: __metaclass__

Instance Methods [hide private]
 
__init__(self, **kwargs)
Cheap initialization.
source code
 
__str__(self)
str(x)
source code
 
__repr__(self, prefixes=[])
String definition of the object of ClassWithCollections object
source code
 
_pretrain(self, dataset)
Functionality prior to training
source code
 
_posttrain(self, dataset)
Functionality post training
source code
 
_getFeatureIds(self)
Virtual method to return feature_ids used while training
source code
 
summary(self)
Providing summary over the classifier
source code
 
clone(self)
Create full copy of the classifier.
source code
 
_train(self, dataset)
Function to be actually overridden in derived classes
source code
 
train(self, dataset)
Train classifier on a dataset
source code
 
_prepredict(self, data)
Functionality prior prediction
source code
 
_postpredict(self, data, result)
Functionality after prediction is computed
source code
 
_predict(self, data)
Actual prediction
source code
 
predict(self, data)
Predict classifier on data
source code
 
isTrained(self, dataset=None)
Either classifier was already trained.
source code
 
_regressionIsBogus(self)
Some classifiers like BinaryClassifier can't be used for regression
source code
 
trained(self)
Either classifier was already trained
source code
 
untrain(self)
Reset trained state
source code
 
getSensitivityAnalyzer(self, **kwargs)
Factory method to return an appropriate sensitivity analyzer for the respective classifier.
source code
 
_setRetrainable(self, value, force=False)
Assign value of retrainable parameter
source code
 
__resetChangedData(self)
For retrainable classifier we keep track of what was changed This function resets that dictionary
source code
 
__wasDataChanged(self, key, entry, update=True)
Check if given entry was changed from what known prior.
source code
 
retrain(self, dataset, **kwargs)
Helper to avoid check if data was changed actually changed
source code
 
repredict(self, data, **kwargs)
Helper to avoid check if data was changed actually changed
source code

Inherited from misc.state.ClassWithCollections: __getattribute__, __new__, __setattr__, reset

Inherited from object: __delattr__, __format__, __hash__, __reduce__, __reduce_ex__, __sizeof__, __subclasshook__

Class Variables [hide private]
  _DEV__doc__ = ...
  trained_labels = StateVariable(enabled= True, doc= "Set of uni...
  trained_nsamples = StateVariable(enabled= True, doc= "Number o...
  trained_dataset = StateVariable(enabled= False, doc= "The data...
  training_confusion = StateVariable(enabled= False, doc= "Confu...
  predictions = StateVariable(enabled= True, doc= "Most recent s...
  values = StateVariable(enabled= True, doc= "Internal classifie...
  training_time = StateVariable(enabled= True, doc= "Time (in se...
  predicting_time = StateVariable(enabled= True, doc= "Time (in ...
  feature_ids = StateVariable(enabled= False, doc= "Feature IDS ...
  _clf_internals = []
Describes some specifics about the classifier -- is that it is doing regression for instance....
  regression = Parameter(False, allowedtype= 'bool', doc= """Eit...
  retrainable = Parameter(False, allowedtype= 'bool', doc= """Ei...

Inherited from misc.state.ClassWithCollections: descr

Instance Variables [hide private]
  __trainednfeatures
Stores number of features for which classifier was trained. If None -- it wasn't trained at all
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **kwargs)
(Constructor)

source code 
Cheap initialization.
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 
str(x)
Overrides: object.__str__
(inherited documentation)

__repr__(self, prefixes=[])
(Representation operator)

source code 
String definition of the object of ClassWithCollections object
Parameters:
  • fullname - Either to include full name of the module
  • prefixes - What other prefixes to prepend to list of arguments
Overrides: object.__repr__
(inherited documentation)

_posttrain(self, dataset)

source code 
Functionality post training

For instance -- computing confusion matrix
:Parameters:
  dataset : Dataset
    Data which was used for training

_getFeatureIds(self)

source code 

Virtual method to return feature_ids used while training

Is not intended to be called anywhere but from _posttrain, thus classifier is assumed to be trained at this point

clone(self)

source code 

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

train(self, dataset)

source code 

Train classifier on a dataset

Shouldn't be overridden in subclasses unless explicitly needed to do so

predict(self, data)

source code 

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

isTrained(self, dataset=None)

source code 

Either classifier was already trained.

MUST BE USED WITH CARE IF EVER

trained(self)

source code 
Either classifier was already trained
Decorators:
  • @property

_setRetrainable(self, value, force=False)

source code 

Assign value of retrainable parameter

If retrainable flag is to be changed, classifier has to be untrained. Also internal attributes such as _changedData, __changedData_isset, and __idhashes should be initialized if it becomes retrainable

__wasDataChanged(self, key, entry, update=True)

source code 

Check if given entry was changed from what known prior.

If so -- store only the ones needed for retrainable beastie

retrain(self, dataset, **kwargs)

source code 

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

repredict(self, data, **kwargs)

source code 

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

Class Variable Details [hide private]

_DEV__doc__

Value:
"""
    Required behavior:

    For every classifier is has to be possible to be instantiated with\
out
    having to specify the training pattern.

    Repeated calls to the train() method with different training data \
...

trained_labels

Value:
StateVariable(enabled= True, doc= "Set of unique labels it has been tr\
ained on")

trained_nsamples

Value:
StateVariable(enabled= True, doc= "Number of samples it has been train\
ed on")

trained_dataset

Value:
StateVariable(enabled= False, doc= "The dataset it has been trained on\
")

training_confusion

Value:
StateVariable(enabled= False, doc= "Confusion matrix of learning perfo\
rmance")

predictions

Value:
StateVariable(enabled= True, doc= "Most recent set of predictions")

values

Value:
StateVariable(enabled= True, doc= "Internal classifier values the most\
 recent "+ "predictions are based on")

training_time

Value:
StateVariable(enabled= True, doc= "Time (in seconds) which took classi\
fier to train")

predicting_time

Value:
StateVariable(enabled= True, doc= "Time (in seconds) which took classi\
fier to predict")

feature_ids

Value:
StateVariable(enabled= False, doc= "Feature IDS which were used for th\
e actual training.")

regression

Value:
Parameter(False, allowedtype= 'bool', doc= """Either to use 'regressio\
n' as regression. By default any
        Classifier-derived class serves as a classifier, so regression
        does binary classification.""", index= 1001)

retrainable

Value:
Parameter(False, allowedtype= 'bool', doc= """Either to enable retrain\
ing for 'retrainable' classifier.""", index= 1002)