Package mvpa :: Package tests :: Module test_lars

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.tests.test_lars

     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 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          # for some reason the R code fails with the dumb data
    24          data = datasets['chirp_linear']
    25
    26
    27          clf = LARS(regression=True)
    28
    29          clf.train(data)
    30
    31          # prediction has to be almost perfect
    32          # test with a correlation
    33          pre = clf.predict(data.samples)
    34          cor = pearsonr(pre, data.labels)
    35          if cfg.getboolean('tests', 'labile', default='yes'):
    36              self.failUnless(cor[0] > .8)
    37
    38 -    def testLARSState(self):
    39          #data = datasets['dumb2']
    40          # for some reason the R code fails with the dumb data
    41          data = datasets['chirp_linear']
    42
    43
    44          clf = LARS()
    45
    46          clf.train(data)
    47
    48          clf.states.enable('predictions')
    49
    50          p = clf.predict(data.samples)
    51
    52          self.failUnless((p == clf.predictions).all())
    53
    54
    55 -    def testLARSSensitivities(self):
    56          data = datasets['chirp_linear']
    57
    58          # use LARS on binary problem
    59          clf = LARS()
    60          clf.train(data)
    61
    62          # now ask for the sensitivities WITHOUT having to pass the dataset
    63          # again
    64          sens = clf.getSensitivityAnalyzer(force_training=False)()
    65
    66          self.failUnless(sens.shape == (data.nfeatures,))
    67
    68
    69 -def suite():
    70      return unittest.makeSuite(LARSTests)
    71
    72
    73  if __name__ == '__main__':
    74      import runner
    75