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

Source Code for Module mvpa.tests.test_ridge

 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 ridge regression classifier""" 
10   
11  from mvpa.clfs.ridge import RidgeReg 
12  from scipy.stats import pearsonr 
13  from tests_warehouse import * 
14   
15 -class RidgeRegTests(unittest.TestCase):
16
17 - def testRidgeReg(self):
18 # not the perfect dataset with which to test, but 19 # it will do for now. 20 data = datasets['dumb'] 21 22 clf = RidgeReg() 23 24 clf.train(data) 25 26 # prediction has to be almost perfect 27 # test with a correlation 28 pre = clf.predict(data.samples) 29 cor = pearsonr(pre,data.labels) 30 self.failUnless(cor[0] > .8)
31 32 # do again for fortran implementation 33 # DISABLE for now, at it is known to be broken 34 # clf = RidgeReg(implementation='gradient') 35 # clf.train(data) 36 # cor = pearsonr(clf.predict(data.samples), data.labels) 37 # print cor 38 # self.failUnless(cor[0] > .8) 39 40 41
42 - def testRidgeRegState(self):
43 data = datasets['dumb'] 44 45 clf = RidgeReg() 46 47 clf.train(data) 48 49 clf.states.enable('predictions') 50 51 p = clf.predict(data.samples) 52 53 self.failUnless((p == clf.predictions).all())
54 55
56 -def suite():
57 return unittest.makeSuite(RidgeRegTests)
58 59 60 if __name__ == '__main__': 61 import runner 62