Changeset 11678:be71dd8a74e4 in orange


Ignore:
Timestamp:
09/02/13 13:19:51 (8 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added test for 'split_by_classifiers' helper.

Location:
Orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/evaluation/scoring.py

    r10984 r11678  
    9898    return ress 
    9999 
     100 
    100101def split_by_classifiers(res): 
    101102    """Split an instance of :obj:`ExperimentResults` into a list of 
     
    115116            r.results[-1].classes = [te.classes[i]] 
    116117            r.results[-1].probabilities = [te.probabilities[i]] 
     118 
     119        if hasattr(res, "examples"): 
     120            r.examples = res.examples 
     121 
    117122        split_res.append(r) 
     123 
    118124    return split_res 
    119125 
  • Orange/testing/unit/tests/test_evaluation_scoring.py

    r10429 r11678  
    264264        return scoring.MCC 
    265265 
     266 
     267class TestUtils(unittest.TestCase): 
     268    def test_split_by_classifier(self): 
     269        learners = [random_learner, random_learner, random_learner] 
     270        ds = data.Table("lenses") 
     271        cv = testing.cross_validation(learners, ds, folds=5) 
     272        cv_split = scoring.split_by_classifiers(cv) 
     273        ca_scores = scoring.CA(cv) 
     274        auc_scores = scoring.AUC(cv) 
     275        for i, cv1 in enumerate(cv_split): 
     276            self.assertEqual(cv1.class_values, cv.class_values) 
     277            self.assertEqual(cv1.classifier_names, [cv.classifier_names[i]]) 
     278            self.assertEqual(cv1.number_of_iterations, cv.number_of_iterations) 
     279            self.assertEqual(cv1.number_of_learners, 1) 
     280            self.assertEqual(cv1.base_class, cv.base_class) 
     281            self.assertEqual(cv1.weights, cv.weights) 
     282            self.assertEqual(len(cv1.results), len(cv.results)) 
     283            self.assertEqual(cv1.examples, cv.examples) 
     284 
     285            ca_one = scoring.CA(cv1)[0] 
     286            auc_one = scoring.AUC(cv1)[0] 
     287            self.assertAlmostEqual(ca_scores[i], ca_one, delta=1e-10) 
     288            self.assertAlmostEquals(auc_scores[i], auc_one, delta=1e-10) 
     289 
     290 
    266291if __name__ == '__main__': 
    267292    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.