Package mvpa :: Package clfs :: Package libsvmc :: Module svm :: Class SVM
[hide private]
[frames] | no frames]

Class SVM

source code


Support Vector Machine Classifier.

This is a simple interface to the libSVM package.

Nested Classes [hide private]

Inherited from misc.state.ClassWithCollections: __metaclass__

Instance Methods [hide private]
 
__init__(self, kernel_type='linear', **kwargs)
This is the base class of all classifier that utilize the libSVM package underneath.
source code
 
_train(self, dataset)
Train SVM
source code
 
_predict(self, data)
Predict values for the data
source code
 
summary(self)
Provide quick summary over the SVM classifier
source code
 
untrain(self)
Reset trained state
source code

Inherited from _svmbase._SVM: __repr__, getSensitivityAnalyzer

Inherited from _svmbase._SVM (private): _getDefaultC, _getDefaultGamma

Inherited from base.Classifier: __str__, isTrained, predict, repredict, retrain, train, trained

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

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

Class Variables [hide private]
  probabilities = StateVariable(enabled= False, doc= "Estimates ...
  _KERNELS = {"linear":(svm.svmc.LINEAR, None, LinearSVMWeights)...
  _KNOWN_PARAMS = ['epsilon', 'probability', 'shrinking', 'weigh...
  _KNOWN_KERNEL_PARAMS = ['cache_size']
  _KNOWN_IMPLEMENTATIONS = {'C_SVC':(svm.svmc.C_SVC, ('C',), ('b...
  _clf_internals = _SVM._clf_internals+ ['libsvm']
Describes some specifics about the classifier -- is that it is doing regression for instance....
  model = property(fget= lambda self: self.__model)
Access to the SVM model.

Inherited from _svmbase._SVM (private): _ATTRIBUTE_COLLECTIONS, _SVM_PARAMS

Inherited from base.Classifier: _DEV__doc__, feature_ids, predicting_time, predictions, regression, retrainable, trained_dataset, trained_labels, training_confusion, training_time, values

Inherited from misc.state.ClassWithCollections: descr

Instance Variables [hide private]
  __model
Holds the trained SVM.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, kernel_type='linear', **kwargs)
(Constructor)

source code 

This is the base class of all classifier that utilize the libSVM package underneath. It is not really meant to be used directly. Unless you know what you are doing it is most likely better to use one of the subclasses.

Here is the explaination for some of the parameters from the libSVM documentation:

svm_type can be one of C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR.

  • C_SVC: C-SVM classification
  • NU_SVC: nu-SVM classification
  • ONE_CLASS: one-class-SVM
  • EPSILON_SVR: epsilon-SVM regression
  • NU_SVR: nu-SVM regression

kernel_type can be one of LINEAR, POLY, RBF, SIGMOID.

  • LINEAR: u'*v
  • POLY: (gamma*u'*v + coef0)^degree
  • RBF: exp(-gamma*|u-v|^2)
  • SIGMOID: tanh(gamma*u'*v + coef0)
  • PRECOMPUTED: kernel values in training_set_file

cache_size is the size of the kernel cache, specified in megabytes. C is the cost of constraints violation. (we usually use 1 to 1000) eps is the stopping criterion. (we usually use 0.00001 in nu-SVC, 0.001 in others). nu is the parameter in nu-SVM, nu-SVR, and one-class-SVM. p is the epsilon in epsilon-insensitive loss function of epsilon-SVM regression. shrinking = 1 means shrinking is conducted; = 0 otherwise. probability = 1 means model with probability information is obtained; = 0 otherwise.

nr_weight, weight_label, and weight are used to change the penalty for some classes (If the weight for a class is not changed, it is set to 1). This is useful for training classifier using unbalanced input data or with asymmetric misclassification cost.

Each weight[i] corresponds to weight_label[i], meaning that the penalty of class weight_label[i] is scaled by a factor of weight[i].

If you do not want to change penalty for any of the classes, just set nr_weight to 0.

Parameters:
  • kernel_type - String must be a valid key for cls._KERNELS
Overrides: object.__init__

_train(self, dataset)

source code 
Train SVM
Overrides: base.Classifier._train

_predict(self, data)

source code 
Predict values for the data
Overrides: base.Classifier._predict

summary(self)

source code 
Provide quick summary over the SVM classifier
Overrides: base.Classifier.summary

untrain(self)

source code 
Reset trained state
Overrides: base.Classifier.untrain
(inherited documentation)

Class Variable Details [hide private]

probabilities

Value:
StateVariable(enabled= False, doc= "Estimates of samples probabilities\
 as provided by LibSVM")

_KERNELS

Value:
{"linear":(svm.svmc.LINEAR, None, LinearSVMWeights), "rbf":(svm.svmc.R\
BF, ('gamma',), None), "poly":(svm.svmc.POLY, ('gamma', 'degree', 'coe\
f0'), None), "sigmoid":(svm.svmc.SIGMOID, ('gamma', 'coef0'), None),}

_KNOWN_PARAMS

Value:
['epsilon', 'probability', 'shrinking', 'weight_label', 'weight']

_KNOWN_IMPLEMENTATIONS

Value:
{'C_SVC':(svm.svmc.C_SVC, ('C',), ('binary', 'multiclass'), 'C-SVM cla\
ssification'), 'NU_SVC':(svm.svmc.NU_SVC, ('nu',), ('binary', 'multicl\
ass'), 'nu-SVM classification'), 'ONE_CLASS':(svm.svmc.ONE_CLASS, (), \
('oneclass',), 'one-class-SVM'), 'EPSILON_SVR':(svm.svmc.EPSILON_SVR, \
('tube_epsilon',), ('regression',), 'epsilon-SVM regression'), 'NU_SVR\
':(svm.svmc.NU_SVR, ('nu',), ('regression',), 'nu-SVM regression')}