pythonpropertiesclassificationsvmsimplecv

How to Change Properties in SimpleCV's SVMClassifier


In the Documentation: SVMClassifier Documentation there are class SimpleCV.MachineLearning.SVMClassifier.SVMClassifier(featureExtractors, properties=None)

Code of class SVMClassifier

    mSVMProperties = {
    'KernelType':'RBF', #default is a RBF Kernel
    'SVMType':'NU',     #default is C 
    'nu':None,          # NU for SVM NU
    'c':None,           #C for SVM C - the slack variable
    'degree':None,      #degree for poly kernels - defaults to 3
    'coef':None,        #coef for Poly/Sigmoid defaults to 0
    'gamma':None,       #kernel param for poly/rbf/sigma - default is 1/#samples       
}

...

        self.mKernelType = {
        'RBF':orange.SVMLearner.RBF, #Radial basis kernel
        'Linear':orange.SVMLearner.Linear, #Linear basis kernel
        'Poly':orange.SVMLearner.Polynomial, #Polynomial kernel
        'Sigmoid':orange.SVMLearner.Sigmoid #Sigmoid Kernel
    }

...

    self.mSVMType = {
        'NU':orange.SVMLearner.Nu_SVC,
        'C':orange.SVMLearner.C_SVC
    }

How to set KernelType? ex:to 'Linear', i've tried with this code

classifier = SVMClassifier(feature_extractors,{'KernelType':'Linear'})

there was an error

 ERROR:
    Traceback (most recent call last):
      File "ntitrasi.py", line 56, in <module>
        classifier = SVMClassifier(feature_extractors,{'KernelType':'Linear'})
      File "C:\Python27\lib\site-packages\simplecv-1.3-py2.7.egg\SimpleCV\MachineLea
    rning\SVMClassifier.py", line 70, in __init__
        self._parameterizeKernel()
      File "C:\Python27\lib\site-packages\simplecv-1.3-py2.7.egg\SimpleCV\MachineLea
    rning\SVMClassifier.py", line 90, in _parameterizeKernel
        self.mSVMPrototype.svm_type = self.mSVMType[self.mSVMProperties["SVMType"]]
    KeyError: 'SVMType'

and i've tried this one too

classifier = SVMClassifier(feature_extractors,{'KernelType':'Linear','SVMType':'C'})

and there was an error too:

ERROR:
Traceback (most recent call last):
  File "ntitrasi.py", line 56, in <module>
    classifier = SVMClassifier(feature_extractors,{'KernelType':'Linear','SVMTyp
e':'C'})
  File "C:\Python27\lib\site-packages\simplecv-1.3-py2.7.egg\SimpleCV\MachineLea
rning\SVMClassifier.py", line 70, in __init__
    self._parameterizeKernel()
  File "C:\Python27\lib\site-packages\simplecv-1.3-py2.7.egg\SimpleCV\MachineLea
rning\SVMClassifier.py", line 92, in _parameterizeKernel
    if(self.mSVMProperties["nu"] is not None):
KeyError: 'nu'

Solution

  • Did you try to include nu in the parameter list?:

    classifier = SVMClassifier(feature_extractors,{'KernelType':'Linear','SVMType':'C','nu':None})?