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