Changeset 8149:053ed129c16d in orange


Ignore:
Timestamp:
08/04/11 16:24:04 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
ab52a7f2165716a85b470ff57f26769047fbe590
Message:

Added test_majority and test_earth.
Added tests to test_measures.

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/misc/testing.py

    r8136 r8149  
    112112 
    113113CLASSIFICATION_DATASETS = ["iris", "brown-selected", "lenses", "monks-1"] 
    114 REGRESSION_DATASETS = ["housing", "auto-mpg"] 
     114REGRESSION_DATASETS = ["housing", "auto-mpg", "servo"] 
    115115CLASSLES_DATASETS =  ["water-treatment"] 
    116116ALL_DATASETS  = CLASSIFICATION_DATASETS + REGRESSION_DATASETS + CLASSLES_DATASETS 
     
    425425    """ MEASURE must be defined in the subclass 
    426426    """ 
     427     
     428    def setUp(self): 
     429        self.measure = self.MEASURE 
    427430             
    428431    @test_on_data 
     
    432435        scores = [] 
    433436        for attr in data.domain.attributes: 
    434             score = self.MEASURE(attr, data) 
     437            score = self.measure(attr, data) 
    435438#            self.assertTrue(score >= 0.0) 
    436439            scores.append(score) 
     
    443446        """ 
    444447        import cPickle 
    445         s = cPickle.dumps(self.MEASURE) 
     448        s = cPickle.dumps(self.measure) 
    446449        measure = cPickle.loads(s) 
    447450        # TODO: make sure measure computes the same scores as measure 
     
    453456    """  
    454457    PREPROCESSOR = None 
     458     
     459    def setUp(self): 
     460        self.preprocessor = self.PREPROCESSOR 
    455461 
    456462    @test_on_data 
     
    458464        """ Test preprocessor on dataset  
    459465        """ 
    460         newdata = self.PREPROCESSOR(dataset) 
     466        newdata = self.preprocessor(dataset) 
    461467         
    462468    def test_pickle(self): 
    463469        """ Test preprocessor pickling 
    464470        """ 
    465         if isinstance(self.PREPROCESSOR, type): 
    466             prep = self.PREPROCESSOR() # Test the default constructed 
     471        if isinstance(self.preprocessor, type): 
     472            prep = self.preprocessor() # Test the default constructed 
    467473            s = cPickle.dumps(prep) 
    468474            prep = cPickle.loads(s) 
    469475                 
    470         s = cPickle.dumps(self.PREPROCESSOR) 
     476        s = cPickle.dumps(self.preprocessor) 
    471477        prep = cPickle.loads(s) 
    472478         
     
    474480from Orange.distance.instances import distance_matrix 
    475481from Orange.misc import member_set 
     482 
    476483 
    477484class DistanceTestCase(DataTestCase): 
  • testing/unittests/tests/test_measures.py

    r8042 r8149  
    11from Orange.misc import testing 
     2from Orange.misc.testing import datasets_driven, test_on_data 
    23from Orange.feature import scoring 
    3 import unittest 
     4import unittest     
     5     
    46 
    5 datasets = testing.CLASSIFICATION_DATASETS + testing.REGRESSION_DATASETS     
     7@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS, 
     8                 preprocess=testing.DISCRETIZE_DOMAIN) 
     9class TestMeasureAttr_GainRatio(testing.MeasureAttributeTestCase): 
     10    MEASURE = scoring.GainRatio() 
    611     
    7 @testing.datasets_driven(datasets=testing.REGRESSION_DATASETS, 
    8                          preprocess=testing.DISCRETIZE_DOMAIN) 
    9 class TestMeasureAttr_MSE(testing.MeasureAttributeTestCase): 
    10     MEASURE = scoring.MSE 
     12     
     13@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS, 
     14                 preprocess=testing.DISCRETIZE_DOMAIN) 
     15class TestMeasureAttr_InfoGain(testing.MeasureAttributeTestCase): 
     16    MEASURE = scoring.InfoGain() 
     17     
     18 
     19# TODO: Relevance, Cost 
     20 
     21@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS, 
     22                 preprocess=testing.DISCRETIZE_DOMAIN) 
     23class TestMeasureAttr_Distance(testing.MeasureAttributeTestCase): 
     24    MEASURE = scoring.Distance() 
     25 
     26     
     27@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS, 
     28                 preprocess=testing.DISCRETIZE_DOMAIN) 
     29class TestMeasureAttr_MDL(testing.MeasureAttributeTestCase): 
     30    MEASURE = scoring.MDL() 
    1131 
    1232 
    13 @testing.datasets_driven(datasets=testing.CLASSIFICATION_DATASETS, 
    14                          preprocess=testing.DISCRETIZE_DOMAIN) 
    15 class TestMeasureAttr_GainRatio(testing.MeasureAttributeTestCase): 
    16     MEASURE = scoring.GainRatio 
     33@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 
     34class TestMeasureAttr_Relief(testing.MeasureAttributeTestCase): 
     35    MEASURE = scoring.Relief() 
     36 
     37 
     38@datasets_driven(datasets=testing.REGRESSION_DATASETS, 
     39                 preprocess=testing.DISCRETIZE_DOMAIN) 
     40class TestMeasureAttr_MSE(testing.MeasureAttributeTestCase): 
     41    MEASURE = scoring.MSE() 
    1742     
    18      
    19 @testing.datasets_driven(datasets=testing.CLASSIFICATION_DATASETS, 
    20                          preprocess=testing.DISCRETIZE_DOMAIN) 
    21 class TestMeasureAttr_InfoGain(testing.MeasureAttributeTestCase): 
    22     MEASURE = scoring.InfoGain 
    23      
    24      
    25 @testing.datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 
    26 class TestMeasureAttr_Relief(testing.MeasureAttributeTestCase): 
    27     MEASURE = scoring.Relief 
    28      
    29      
     43 
     44@datasets_driven(datasets=testing.CLASSIFICATION_DATASETS) 
     45class TestScoringUtils(testing.DataTestCase): 
     46    @test_on_data 
     47    def test_order_attrs(self, dataset): 
     48        order = scoring.OrderAttributes(scoring.Relief()) 
     49        orderes_attrs = order(dataset, 0) 
     50         
     51    @test_on_data 
     52    def test_score_all(self, dataset): 
     53        scoring.score_all(dataset, measure=scoring.Relief()) 
     54          
     55         
    3056if __name__ == "__main__": 
    3157    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.