Package mvpa :: Package tests :: Module tests_warehouse_clfs
[hide private]
[frames] | no frames]

Source Code for Module mvpa.tests.tests_warehouse_clfs

 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  """Provides `clfs` dictionary with instances of all available classifiers.""" 
10   
11  __docformat__ = 'restructuredtext' 
12   
13  # 
14  # first deal with classifiers which do not have external deps 
15  # 
16  from mvpa.clfs.smlr import SMLR 
17  from mvpa.clfs.knn import * 
18   
19  from mvpa.clfs.warehouse import clfswh, regrswh 
20  from mvpa.base import externals 
21   
22  # if have ANY svm implementation 
23  if externals.exists('libsvm') or externals.exists('shogun'): 
24      from mvpa.clfs.svm import * 
25   
26  # 
27  # Few silly classifiers 
28  # 
29 -class SameSignClassifier(Classifier):
30 """Dummy classifier which reports +1 class if both features have 31 the same sign, -1 otherwise""" 32 33 _clf_internals = ['notrain2predict']
34 - def __init__(self, **kwargs):
35 Classifier.__init__(self, **kwargs)
36
37 - def _train(self, data):
38 # we don't need that ;-) 39 pass
40
41 - def _predict(self, data):
42 datalen = len(data) 43 values = [] 44 for d in data: 45 values.append(2*int( (d[0]>=0) == (d[1]>=0) )-1) 46 self.predictions = values 47 self.values = values # just for the sake of having values 48 return values
49 50
51 -class Less1Classifier(SameSignClassifier):
52 """Dummy classifier which reports +1 class if abs value of max less than 1"""
53 - def _predict(self, data):
54 datalen = len(data) 55 values = [] 56 for d in data: 57 values.append(2*int(max(d)<=1)-1) 58 self.predictions = values 59 return values
60 61 # Sample universal classifiers (linear and non-linear) which should be 62 # used whenever it doesn't matter what classifier it is for testing 63 # some higher level creations -- chosen so it is the fastest universal 64 # one. Also it should not punch state.py in the face how it is 65 # happening with kNN... 66 sample_clf_lin = SMLR(lm=0.1)#sg.svm.LinearCSVMC(svm_impl='libsvm') 67 68 #if externals.exists('shogun'): 69 # sample_clf_nl = sg.SVM(kernel_type='RBF', svm_impl='libsvm') 70 #else: 71 #classical one which was used for a while 72 #and surprisingly it is not bad at all for the unittests 73 sample_clf_nl = kNN(k=5) 74 75 # and also a regression-based classifier 76 r = clfswh['linear', 'regression', 'has_sensitivity'] 77 if len(r) > 0: sample_clf_reg = r[0] 78 else: sample_clf_reg = None 79