Changeset 10429:23daf949f7b2 in orange


Ignore:
Timestamp:
03/02/12 16:56:57 (2 years ago)
Author:
anzeh <anze.staric@…>
Branch:
default
Message:

Fixed some backward compatibility issues.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Orange/evaluation/scoring.py

    r10426 r10429  
    775775                         or list of :obj:`ConfusionMatrix`. 
    776776    :rtype: list of scores, one for each learner.""" 
     777    def __new__(cls, test_results, **kwargs): 
     778        self = list.__new__(cls) 
     779        if isinstance(test_results, ConfusionMatrix): 
     780            self.__init__(test_results, **kwargs) 
     781            return self[0] 
     782        return self 
     783 
     784 
    777785    @deprecated_keywords({"confm": "test_results"}) 
    778786    def __init__(self, test_results=None): 
  • Orange/testing/unit/tests/test_evaluation_scoring.py

    r10426 r10429  
    186186        self.assertIsInstance(scores, list) 
    187187 
     188    def test_with_confusion_matrices_on_biclass(self): 
     189        learner = random_learner 
     190        ds = data.Table("monks-1") 
     191        pt = testing.proportion_test([learner], ds, times=1) 
     192        cm = scoring.confusion_matrices(pt, class_index=1) 
     193        scores = self.score(cm) 
     194        self.assertIsInstance(scores, list) 
     195 
     196    def test_with_confusion_matrices_on_multiclass(self): 
     197        learner = random_learner 
     198        ds = data.Table("iris") 
     199        pt = testing.proportion_test([learner], ds, times=1) 
     200        cm = scoring.confusion_matrices(pt, class_index=1) 
     201        scores = self.score(cm) 
     202        self.assertIsInstance(scores, list) 
     203 
    188204    def test_with_confusion_matrix_on_biclass(self): 
    189205        learner = random_learner 
     
    191207        pt = testing.proportion_test([learner], ds, times=1) 
    192208        cm = scoring.confusion_matrices(pt, class_index=1) 
    193         scores = self.score(cm) 
    194         self.assertIsInstance(scores, list) 
     209        scores = self.score(cm[0]) 
     210        self.assertIsInstance(scores, float) 
    195211 
    196212    def test_with_confusion_matrix_on_multiclass(self): 
     
    199215        pt = testing.proportion_test([learner], ds, times=1) 
    200216        cm = scoring.confusion_matrices(pt, class_index=1) 
    201         scores = self.score(cm) 
    202         self.assertIsInstance(scores, list) 
     217        scores = self.score(cm[0]) 
     218        self.assertIsInstance(scores, float) 
     219 
    203220 
    204221class TestSensitivity(CMScoreTest, unittest.TestCase): 
  • docs/reference/rst/code/statExamples.py

    r9945 r10429  
    6868 
    6969cm = Orange.evaluation.scoring.confusion_matrices(res) 
     70sensitivities = Orange.evaluation.scoring.sens(cm) 
     71specificities = Orange.evaluation.scoring.spec(cm) 
    7072print 
    7173print "Sensitivity and specificity for 'voting'" 
    7274print "method\tsens\tspec" 
    7375for l in range(len(learners)): 
    74     print "%s\t%5.3f\t%5.3f" % (learners[l].name, Orange.evaluation.scoring.sens(cm[l]), Orange.evaluation.scoring.spec(cm[l])) 
     76    print "%s\t%5.3f\t%5.3f" % (learners[l].name, sensitivities[l], specificities[l]) 
    7577 
    7678cm = Orange.evaluation.scoring.confusion_matrices(resVeh, vehicle.domain.class_var.values.index("van")) 
     79sensitivities = Orange.evaluation.scoring.sens(cm) 
     80specificities = Orange.evaluation.scoring.spec(cm) 
    7781print 
    7882print "Sensitivity and specificity for 'vehicle=van'" 
    7983print "method\tsens\tspec" 
    8084for l in range(len(learners)): 
    81     print "%s\t%5.3f\t%5.3f" % (learners[l].name, Orange.evaluation.scoring.sens(cm[l]), Orange.evaluation.scoring.spec(cm[l])) 
     85    print "%s\t%5.3f\t%5.3f" % (learners[l].name, sensitivities[l], specificities[l]) 
    8286 
    8387print 
Note: See TracChangeset for help on using the changeset viewer.