source: orange/Orange/testing/unit/tests/test_linear.py @ 10278:f3b1ffae9c29

Revision 10278:f3b1ffae9c29, 2.0 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Unittest2 for python 2.6.

Line 
1import Orange
2from Orange.misc import testing
3from Orange.misc.testing import datasets_driven
4from Orange.classification.svm import LinearLearner
5try:
6    import unittest2 as unittest
7except:
8    import unittest
9
10
11@testing.test_on_data
12def test_learner_on(self, dataset):
13    testing.LearnerTestCase.test_learner_on(self, dataset)
14    n_vals = len(dataset.domain.class_var.values)
15    if n_vals > 2:
16        self.assertEquals(len(self.classifier.weights), n_vals)
17    else:
18        self.assertEquals(len(self.classifier.weights), 1)
19
20    n_features = len(dataset.domain.attributes)
21    self.assert_(all(len(w) == n_features for w in self.classifier.weights))
22
23@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
24class TestLinearLearnerL2R_L2LOSS_DUAL(testing.LearnerTestCase):
25    LEARNER = LinearLearner(sover_type=LinearLearner.L2R_L2LOSS_DUAL)
26
27    test_learner_on = test_learner_on
28
29@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
30class TestLinearLearnerL2R_L2LOSS(testing.LearnerTestCase):
31    LEARNER = LinearLearner(sover_type=LinearLearner.L2R_L2LOSS)
32    test_learner_on = test_learner_on
33
34@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
35class TestLinearLearnerL2R_L1LOSS_DUAL(testing.LearnerTestCase):
36    LEARNER = LinearLearner(sover_type=LinearLearner.L2R_L1LOSS_DUAL)
37    test_learner_on = test_learner_on
38
39@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
40class TestLinearLearnerL2R_L1LOSS(testing.LearnerTestCase):
41    LEARNER = LinearLearner(sover_type=LinearLearner.L2R_L2LOSS)
42    test_learner_on = test_learner_on
43
44@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
45class TestLinearLearnerL1R_L2LOSS(testing.LearnerTestCase):
46    LEARNER = LinearLearner(sover_type=LinearLearner.L1R_L2LOSS)
47    test_learner_on = test_learner_on
48
49@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS)
50class TestLinearLearnerL1R_L2LOSS(testing.LearnerTestCase):
51    LEARNER = LinearLearner(sover_type=LinearLearner.MCSVM_CS)
52    test_learner_on = test_learner_on
53
54if __name__ == "__main__":
55    unittest.main()
Note: See TracBrowser for help on using the repository browser.