Package PyML :: Package classifiers :: Module svm :: Class SVM
[frames] | no frames]

Class SVM

source code

base.pymlObject.PyMLobject --+    
                             |    
    baseClassifiers.Classifier --+
                                 |
                                SVM

An SVM classifier class.

SVM is trained using either libsvm, or using a PyML SMO implementation based on libsvm

Nested Classes
    Inherited from baseClassifiers.Classifier
  resultsObject
Instance Methods
 
__init__(self, arg=None, **args) source code
 
__repr__(self) source code
 
save(self, fileName)
save an SVM model to a file.
source code
 
train(self, data, **args)
train an SVM
source code
 
modelDispatcher(self, data, svID, alpha, b, **args) source code
 
trainLibsvm(self, data, **args) source code
 
getC(self, data) source code
 
trainGist(self, data, **args) source code
 
trainGradient(self, data, **args) source code
 
trainMySMO(self, data, **args) source code
 
decisionFunc(self, data, i) source code
 
classify(self, data, i) source code
    Inherited from baseClassifiers.Classifier
 
cv(classifier, data, numFolds=5, **args)
perform k-fold cross validation
source code
 
getTrainingTime(self) source code
 
logger(self) source code
 
loo(classifier, data, **args)
perform Leave One Out
source code
 
nCV(classifier, data, **args)
runs CV n times, returning a 'ResultsList' object.
source code
 
project(self, data)
project a test dataset to the training data features.
source code
 
stratifiedCV(classifier, data, numFolds=5, **args)
perform k-fold stratified cross-validation; in each fold the number of patterns from each class is proportional to the relative fraction of the class in the dataset
source code
 
test(classifier, data, **args)
test a classifier on a given dataset
source code
 
trainFinalize(self) source code
 
trainTest(classifierTemplate, data, trainingPatterns, testingPatterns, **args)
Train a classifier on the list of training patterns, and test it on the test patterns
source code
 
twoClassClassify(self, data, i) source code
Class Variables
  svm_type = C_SVC
  attributes = {'C': 10, 'nu': 0.5, 'Cmode': 'classProb', 'optim...
    Inherited from baseClassifiers.Classifier
  deepcopy = False
  type = 'classifier'
Method Details

__init__(self, arg=None, **args)
(Constructor)

source code 
Parameters:
  • arg - another SVM object or a kernel object; if no argument is given the kernel function of the training dataset is used
  • C - the svm C parameter
  • Cmode - the way the C parameter is used; values: 'equal', 'classProb', 'fromData'. In 'equal' mode C is set to be the same for both classes In 'classProb' mode each class is assigned a C value that is proportional to the size of the other class. This results in margin error costs being proportional to the ratio of the sizes of the two classes. This is useful for datasets with an unbalanced class distribution. In 'fromData' the value of C for each pattern is taken from the 'C' attribute of the training data.
  • optimizer - which optimizer to use. values: 'libsvm' -- run libsvm 'mysmo' - use the PyML native optmizer (based on libsvm) 'gist' - use a gist-like optimizer.
  • cacheSize - size of the kernel cache (in MB).
Overrides: baseClassifiers.Classifier.__init__

__repr__(self)
(Representation operator)

source code 
Overrides: baseClassifiers.Classifier.__repr__

save(self, fileName)

source code 
save an SVM model to a file. use the loadSVM method to then load the saved model be sure the call the SVM train function as: train(data, saveSpace=False)
Parameters:
  • fileName - a file name or file handle
Overrides: baseClassifiers.Classifier.save

train(self, data, **args)

source code 
train an SVM
Parameters:
  • saveSpace - - whether to save memory when constructing an SVM model [default: True] you need to set this keyword to False if you want to save the resulting model
Overrides: baseClassifiers.Classifier.train

classify(self, data, i)

source code 
Overrides: baseClassifiers.Classifier.classify

Class Variable Details

attributes

Value:
{'C': 10, 'nu': 0.5, 'Cmode': 'classProb', 'optimizer': 'libsvm', 'cac\
heSize': 256, 'nu': 0.1, 'eps': 0.01}