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

Source Code for Module mvpa.tests.test_regr

 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 Regressions""" 
10   
11  from mvpa.base import externals 
12  from mvpa.support.copy import deepcopy 
13   
14  from mvpa.datasets import Dataset 
15  from mvpa.mappers.mask import MaskMapper 
16  from mvpa.datasets.splitters import NFoldSplitter 
17   
18  from mvpa.misc.errorfx import RMSErrorFx, RelativeRMSErrorFx, \ 
19       CorrErrorFx, CorrErrorPFx 
20   
21  from mvpa.clfs.transerror import TransferError 
22  from mvpa.misc.exceptions import UnknownStateError 
23   
24  from mvpa.algorithms.cvtranserror import CrossValidatedTransferError 
25   
26  from tests_warehouse import * 
27  from tests_warehouse_clfs import * 
28   
29 -class RegressionsTests(unittest.TestCase):
30 31 @sweepargs(ml=clfswh['regression']+regrswh[:])
32 - def testNonRegressions(self, ml):
33 """Test If binary regression-based classifiers have proper tag 34 """ 35 self.failUnless(('binary' in ml._clf_internals) != ml.regression, 36 msg="Inconsistent markin with " 37 "binary and regression features detected")
38 39 @sweepargs(regr=regrswh['regression'])
40 - def testRegressions(self, regr):
41 """Simple tests on regressions 42 """ 43 ds = datasets['chirp_linear'] 44 45 cve = CrossValidatedTransferError( 46 TransferError(regr, CorrErrorFx()), 47 splitter=NFoldSplitter(), 48 enable_states=['training_confusion', 'confusion']) 49 corr = cve(ds) 50 51 #TODO: test confusion statistics 52 s0 = cve.confusion.asstring(short=True) 53 s1 = cve.confusion.asstring(short=False) 54 55 for s in [s0, s1]: 56 self.failUnless(len(s) > 10, 57 msg="We should get some string representation " 58 "of regression summary. Got %s" % s) 59 60 self.failUnless(corr<0.2, 61 msg="Regressions should perform well on a simple " 62 "dataset. Got correlation error of %s " % corr) 63 64 # Test access to summary statistics 65 self.failUnless(cve.confusion.stats['Summary CCe'] < 0.5)
66 67 # To test basic plotting 68 #import pylab as P 69 #cve.confusion.plot() 70 #P.show() 71 72 @sweepargs(clf=clfswh['regression'])
73 - def testRegressionsClassifiers(self, clf):
74 """Simple tests on regressions being used as classifiers 75 """ 76 # check if we get values set correctly 77 clf.states._changeTemporarily(enable_states=['values']) 78 self.failUnlessRaises(UnknownStateError, clf.states['values']._get) 79 cv = CrossValidatedTransferError( 80 TransferError(clf), 81 NFoldSplitter(), 82 enable_states=['confusion', 'training_confusion']) 83 ds = datasets['uni2small'] 84 cverror = cv(ds) 85 self.failUnless(len(clf.values) == ds['chunks', 1].nsamples) 86 clf.states._resetEnabledTemporarily()
87 88
89 -def suite():
90 return unittest.makeSuite(RegressionsTests)
91 92 93 if __name__ == '__main__': 94 import runner 95