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

Source Code for Module mvpa.clfs.svm

 1  #emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- 
 2  #ex: set sts=4 ts=4 sw=4 et: 
 3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## 
 4  # 
 5  #   See COPYING file distributed along with the PyMVPA package for the 
 6  #   copyright and license terms. 
 7  # 
 8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## 
 9  """Wrap the libsvm package into a very simple class interface.""" 
10   
11  __docformat__ = 'restructuredtext' 
12   
13  # take care of conditional import of external classifiers 
14  import mvpa.base.externals as externals 
15  from mvpa.misc import warning 
16   
17  from _svmbase import _SVM 
18   
19  # default SVM implementation 
20  SVM = None 
21  _NuSVM = None 
22  if externals.exists('shogun'): 
23      from mvpa.clfs import sg 
24      SVM = sg.SVM 
25      #if not 'LinearCSVMC' in locals(): 
26      #    from mvpa.clfs.sg.svm import * 
27   
28  if externals.exists('libsvm'): 
29      # By default for now we want simply to import all SVMs from libsvm 
30      from mvpa.clfs import libsvm 
31      _NuSVM = libsvm.SVM 
32      SVM = libsvm.SVM 
33      #from mvpa.clfs.libsvm.svm import * 
34   
35   
36  if SVM is None: 
37      warning("None of SVM implementions libraries was found") 
38  else: 
39      _defaultC = _SVM._SVM_PARAMS['C'].default 
40      _defaultNu = _SVM._SVM_PARAMS['nu'].default 
41   
42      # Define some convinience classes 
43 - class LinearCSVMC(SVM):
44 """C-SVM classifier using linear kernel. 45 46 See help for %s for more details 47 """ % SVM.__class__.__name__ 48
49 - def __init__(self, C=_defaultC, **kwargs):
50 """ 51 """ 52 # init base class 53 SVM.__init__(self, C=C, kernel_type='linear', **kwargs)
54 55
56 - class RbfCSVMC(SVM):
57 """C-SVM classifier using a radial basis function kernel. 58 59 See help for %s for more details 60 """ % SVM.__class__.__name__ 61
62 - def __init__(self, C=_defaultC, **kwargs):
63 """ 64 """ 65 # init base class 66 SVM.__init__(self, C=C, kernel_type='RBF', **kwargs)
67 68 if _NuSVM is not None:
69 - class LinearNuSVMC(_NuSVM):
70 """Nu-SVM classifier using linear kernel. 71 72 See help for %s for more details 73 """ % _NuSVM.__class__.__name__ 74
75 - def __init__(self, nu=_defaultNu, **kwargs):
76 """ 77 """ 78 # init base class 79 _NuSVM.__init__(self, nu=nu, kernel_type='linear', **kwargs)
80
81 - class RbfNuSVMC(SVM):
82 """Nu-SVM classifier using a radial basis function kernel. 83 84 See help for %s for more details 85 """ % SVM.__class__.__name__ 86
87 - def __init__(self, nu=_defaultNu, **kwargs):
88 # init base class 89 SVM.__init__(self, nu=nu, kernel_type='RBF', **kwargs)
90