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

Source Code for Module mvpa.tests.test_smlr

 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  """Unit tests for PyMVPA sparse multinomial logistic regression classifier""" 
10   
11  from mvpa.clfs.smlr import SMLR 
12  from tests_warehouse import * 
13  from mvpa.misc.data_generators import normalFeatureDataset 
14   
15   
16 -class SMLRTests(unittest.TestCase):
17
18 - def testSMLR(self):
19 data = datasets['dumb'] 20 21 clf = SMLR() 22 23 clf.train(data) 24 25 # prediction has to be perfect 26 # 27 # XXX yoh: whos said that?? ;-) 28 # 29 # There is always a tradeoff between learning and 30 # generalization errors so... but in this case the problem is 31 # more interesting: absent bias disallows to learn data you 32 # have here -- there is no solution which would pass through 33 # (0,0) 34 predictions = clf.predict(data.samples) 35 self.failUnless((predictions == data.labels).all())
36 37
38 - def testSMLRState(self):
39 data = datasets['dumb'] 40 41 clf = SMLR() 42 43 clf.train(data) 44 45 clf.states.enable('values') 46 clf.states.enable('predictions') 47 48 p = N.asarray(clf.predict(data.samples)) 49 50 self.failUnless((p == clf.predictions).all()) 51 self.failUnless(N.array(clf.values).shape[0] == N.array(p).shape[0])
52 53
54 - def testSMLRSensitivities(self):
55 data = normalFeatureDataset(perlabel=10, nlabels=2, nfeatures=4) 56 57 # use SMLR on binary problem, but not fitting all weights 58 clf = SMLR(fit_all_weights=False) 59 clf.train(data) 60 61 # now ask for the sensitivities WITHOUT having to pass the dataset 62 # again 63 sens = clf.getSensitivityAnalyzer(force_training=False)() 64 65 self.failUnless(sens.shape == (data.nfeatures,))
66 67
68 -def suite():
69 return unittest.makeSuite(SMLRTests)
70 71 72 if __name__ == '__main__': 73 import runner 74