1
2
3
4
5
6
7
8
9 """Wrap the libsvm package into a very simple class interface."""
10
11 __docformat__ = 'restructuredtext'
12
13
14 from mvpa.base import warning, cfg, externals
15 from _svmbase import _SVM
16
17 if __debug__:
18 from mvpa.base import debug
19
20
21 SVM = None
22 _NuSVM = None
23
24
25
26 _VALID_BACKENDS = ('libsvm', 'shogun', 'sg')
27 default_backend = cfg.get('svm', 'backend', default='libsvm').lower()
28 if default_backend == 'shogun':
29 default_backend = 'sg'
30
31 if not default_backend in _VALID_BACKENDS:
32 raise ValueError, 'Configuration option svm.backend got invalid value %s.' \
33 ' Valid choices are %s' % (default_backend, _VALID_BACKENDS)
34
35 if __debug__:
36 debug('SVM', 'Default SVM backend is %s' % default_backend)
37
38 if externals.exists('shogun'):
39 from mvpa.clfs import sg
40 SVM = sg.SVM
41
42
43
44 if externals.exists('libsvm'):
45
46 from mvpa.clfs import libsvmc
47 _NuSVM = libsvmc.SVM
48 if default_backend == 'libsvm' or SVM is None:
49 if __debug__ and default_backend != 'libsvm' and SVM is None:
50 debug('SVM',
51 'Default SVM backend %s was not found, so using libsvm'
52 % default_backend)
53 SVM = libsvmc.SVM
54
55
56 if SVM is None:
57 warning("None of SVM implementions libraries was found")
58 else:
59 _defaultC = _SVM._SVM_PARAMS['C'].default
60 _defaultNu = _SVM._SVM_PARAMS['nu'].default
61
62
64 """C-SVM classifier using linear kernel.
65
66 See help for %s for more details
67 """ % SVM.__class__.__name__
68
70 """
71 """
72
73 SVM.__init__(self, C=C, kernel_type='linear', **kwargs)
74
75
77 """C-SVM classifier using a radial basis function kernel.
78
79 See help for %s for more details
80 """ % SVM.__class__.__name__
81
83 """
84 """
85
86 SVM.__init__(self, C=C, kernel_type='RBF', **kwargs)
87
88 if _NuSVM is not None:
90 """Nu-SVM classifier using linear kernel.
91
92 See help for %s for more details
93 """ % _NuSVM.__class__.__name__
94
96 """
97 """
98
99 _NuSVM.__init__(self, nu=nu, kernel_type='linear', **kwargs)
100
102 """Nu-SVM classifier using a radial basis function kernel.
103
104 See help for %s for more details
105 """ % SVM.__class__.__name__
106
108
109 SVM.__init__(self, nu=nu, kernel_type='RBF', **kwargs)
110