source: orange/Orange/testing/unit/tests/test_logreg.py @ 11061:ea7f2080d8b4

Revision 11061:ea7f2080d8b4, 2.3 KB checked in by Yuval Greenfield <yuval@…>, 15 months ago (diff)

Added a test case for logreg.dump and a high beta classifier.

Line 
1from Orange.testing import testing
2try:
3    import unittest2 as unittest
4except:
5    import unittest
6
7from orngLR import LogRegLearner, Univariate_LogRegLearner, StepWiseFSS, StepWiseFSS_Filter
8
9from Orange.classification.logreg import LibLinearLogRegLearner, dump
10import Orange
11
12def datasets_iter():
13    for name, (data,) in testing.datasets_iter(testing.CLASSIFICATION_DATASETS):
14        if len(data.domain.class_var.values) == 2:
15            yield name, (data,)
16
17
18@testing.data_driven(data_iter=datasets_iter())
19class TestLogRegLearner(testing.LearnerTestCase):
20    LEARNER = LogRegLearner
21    @testing.test_on_data
22    def test_learner_on(self, dataset):
23        """ Test LogRegLearner.
24        """
25        if len(dataset) < len(dataset.domain):
26            raise unittest.SkipTest("Not enough examples")
27        testing.LearnerTestCase.test_learner_on(self, dataset)
28
29
30@testing.data_driven(data_iter=datasets_iter())
31class TestStepWiseFSS(unittest.TestCase):
32    @testing.test_on_data
33    def test_stepwise_fss_on(self, dataset):
34        """ Test StepWiseFSS.
35        """
36        if len(dataset) < len(dataset.domain):
37            raise unittest.SkipTest("No enough examples")
38
39        attrs = StepWiseFSS(dataset)
40        new_dataset = StepWiseFSS_Filter(dataset)
41        self.assertTrue([a1 == a2 for a1, a2 in zip(attrs, new_dataset.domain.attributes)])
42
43@testing.datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
44class TestLibLinearLogRegLearner(testing.LearnerTestCase):
45    LEARNER = LibLinearLogRegLearner
46    @testing.test_on_data
47    def test_learner_on(self, dataset):
48        """ Test LibLinearLogRegLearner.
49        """
50        testing.LearnerTestCase.test_learner_on(self, dataset)
51
52class TestUtils(unittest.TestCase):
53    def test_dump(self):
54        """Test for dump() failing (OverflowError: math range error on math.exp)
55         on classifiers with high beta"""
56        quality = Orange.feature.Discrete('quality')
57        quality.add_value('low')
58        quality.add_value('high')
59        price = Orange.feature.Continuous('price')
60        variables = [price, quality]
61        matrix = [[0.01, 'high'], [0.001, 'low']]
62        domain = Orange.data.Domain(variables)
63        data = Orange.data.Table(domain, matrix)
64        classifier = LogRegLearner(data)
65        text_dump = dump(classifier)
66
67
68if __name__ == "__main__":
69    unittest.main()
Note: See TracBrowser for help on using the repository browser.