Changeset 10021:d08881da2dbb in orange


Ignore:
Timestamp:
02/07/12 16:06:09 (2 years ago)
Author:
Lan Zagar <lan.zagar@…>
Branch:
default
rebase_source:
20f2b6377fd14d4fa4dd09ba7f40474fca3dfd96
Message:

Added multitarget support to testing and experiment results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/evaluation/testing.py

    r10020 r10021  
    88TEST_TYPE_SINGLE = 0 
    99TEST_TYPE_MLC = 1 
     10TEST_TYPE_MULTITARGET = 2 
    1011 
    1112class TestedExample: 
     
    3839        """Appends a new result (class and probability prediction by a single classifier) to the classes and probabilities field.""" 
    3940     
    40         if type(aclass)==int: 
    41             self.classes.append(int(aclass)) 
    42             self.probabilities.append(list(aprob)) 
     41        if isinstance(aclass, (list, tuple)): 
     42            self.classes.append(aclass) 
     43            self.probabilities.append(aprob) 
    4344        elif type(aclass.value)==float: 
    4445            self.classes.append(float(aclass)) 
    4546            self.probabilities.append(aprob) 
    4647        else: 
    47             self.classes.append(aclass) 
    48             self.probabilities.append(aprob) 
     48            self.classes.append(int(aclass)) 
     49            self.probabilities.append(list(aprob)) 
    4950 
    5051    def set_result(self, i, aclass, aprob): 
    5152        """Sets the result of the i-th classifier to the given values.""" 
    52         if type(aclass)==list: 
     53        if isinstance(aclass, (list, tuple)): 
    5354            self.classes[i] = aclass 
    5455            self.probabilities[i] = aprob 
     
    108109        if domain is not None: 
    109110            self.base_class = self.class_values = None 
    110             if test_type==TEST_TYPE_SINGLE: 
     111            if test_type == TEST_TYPE_SINGLE: 
    111112                if domain.class_var.var_type == Orange.feature.Type.Discrete: 
    112113                    self.class_values = list(domain.class_var.values) 
     
    115116                else: 
    116117                    self.converter = float 
    117             elif test_type==TEST_TYPE_MLC: 
     118            elif test_type in (TEST_TYPE_MLC, TEST_TYPE_MULTITARGET): 
    118119                self.labels = [var.name for var in domain.class_vars] 
    119120                self.converter = lambda vals: [int(val) if val.variable.var_type == Orange.feature.Type.Discrete 
     
    704705        if multi_label and not all(model_is_mlc): 
    705706            raise ValueError("Test on mixed types of learners (MLC and non-MLC) not possible") 
    706  
    707         if multi_label and not instances.domain.class_vars: 
     707        multi_target = instances.domain.class_vars and not multi_label 
     708 
     709        if (multi_label or multi_target) and not instances.domain.class_vars: 
    708710            raise ValueError("Test data with multiple labels (class vars) expected") 
    709         if not multi_label and not instances.domain.class_var: 
     711        if not (multi_label or multi_target or instances.domain.class_var): 
    710712            raise ValueError("Test data set without class attributes") 
    711713 
    712         return TEST_TYPE_MLC if multi_label else TEST_TYPE_SINGLE 
     714        return TEST_TYPE_MLC if multi_label else ( 
     715            TEST_TYPE_MULTITARGET if multi_target else TEST_TYPE_SINGLE) 
    713716     
    714717default_evaluation = _default_evaluation = Evaluation() 
Note: See TracChangeset for help on using the changeset viewer.