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

Source Code for Module mvpa.tests.test_lars

 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  """Unit tests for PyMVPA least angle regression (LARS) classifier""" 
10   
11  from mvpa import cfg 
12  from mvpa.clfs.lars import LARS 
13  from scipy.stats import pearsonr 
14  from tests_warehouse import * 
15  from mvpa.misc.data_generators import normalFeatureDataset 
16   
17 -class LARSTests(unittest.TestCase):
18
19 - def testLARS(self):
20 # not the perfect dataset with which to test, but 21 # it will do for now. 22 data = datasets['dumb2'] 23 24 clf = LARS(regression=True) 25 26 clf.train(data) 27 28 # prediction has to be almost perfect 29 # test with a correlation 30 pre = clf.predict(data.samples) 31 cor = pearsonr(pre, data.labels) 32 if cfg.getboolean('tests', 'labile', default='yes'): 33 self.failUnless(cor[0] > .8)
34
35 - def testLARSState(self):
36 data = datasets['dumb2'] 37 38 clf = LARS() 39 40 clf.train(data) 41 42 clf.states.enable('predictions') 43 44 p = clf.predict(data.samples) 45 46 self.failUnless((p == clf.predictions).all())
47 48
49 - def testLARSSensitivities(self):
50 data = normalFeatureDataset(perlabel=10, nlabels=2, nfeatures=4) 51 52 # use LARS on binary problem 53 clf = LARS() 54 clf.train(data) 55 56 # now ask for the sensitivities WITHOUT having to pass the dataset 57 # again 58 sens = clf.getSensitivityAnalyzer(force_training=False)() 59 60 self.failUnless(sens.shape == (data.nfeatures,))
61 62
63 -def suite():
64 return unittest.makeSuite(LARSTests)
65 66 67 if __name__ == '__main__': 68 import runner 69