Ignore:
Timestamp:
03/15/12 15:34:09 (2 years ago)
Author:
anzeh <anze.staric@…>
Branch:
default
Parents:
10542:7dde0640e266 (diff), 10534:70534adf6275 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/feature/scoring.py

    r10524 r10543  
    1 import Orange.core as orange 
    2 import Orange.misc 
    3  
    4 from orange import MeasureAttribute as Score 
    5 from orange import MeasureAttributeFromProbabilities as ScoreFromProbabilities 
    6 from orange import MeasureAttribute_info as InfoGain 
    7 from orange import MeasureAttribute_gainRatio as GainRatio 
    8 from orange import MeasureAttribute_gini as Gini 
    9 from orange import MeasureAttribute_relevance as Relevance  
    10 from orange import MeasureAttribute_cost as Cost 
    11 from orange import MeasureAttribute_relief as Relief 
    12 from orange import MeasureAttribute_MSE as MSE 
     1from Orange import core, feature 
     2from Orange.statistics import contingency, distribution 
     3 
     4from Orange.misc import deprecated_keywords, deprecated_members 
     5 
     6Score = core.MeasureAttribute 
     7ScoreFromProbabilities = core.MeasureAttributeFromProbabilities 
     8InfoGain = core.MeasureAttribute_info 
     9GainRatio = core.MeasureAttribute_gainRatio 
     10Gini = core.MeasureAttribute_gini 
     11Relevance = core.MeasureAttribute_relevance 
     12Cost = core.MeasureAttribute_cost 
     13Relief = core.MeasureAttribute_relief 
     14MSE = core.MeasureAttribute_MSE 
    1315 
    1416###### 
     
    3133 
    3234        :param data: a data table used to score features 
    33         :type data: Orange.data.Table 
     35        :type data: :obj:`~Orange.data.Table` 
    3436 
    3537        :param weight: meta attribute that stores weights of instances 
    36         :type weight: Orange.feature.Descriptor 
     38        :type weight: :obj:`~Orange.feature.Descriptor` 
    3739 
    3840        """ 
     
    4648        return [x[0] for x in measured] 
    4749 
    48 OrderAttributes = Orange.misc.deprecated_members({ 
     50OrderAttributes = deprecated_members({ 
    4951          "measure": "score", 
    5052}, wrap_methods=[])(OrderAttributes) 
     
    5961    """ 
    6062 
    61     @Orange.misc.deprecated_keywords({"aprioriDist": "apriori_dist"}) 
     63    @deprecated_keywords({"aprioriDist": "apriori_dist"}) 
    6264    def __new__(cls, attr=None, data=None, apriori_dist=None, weightID=None): 
    6365        self = Score.__new__(cls) 
    64         if attr != None and data != None: 
     66        if attr is not None and data is not None: 
    6567            #self.__init__(**argkw) 
    6668            return self.__call__(attr, data, apriori_dist, weightID) 
     
    6870            return self 
    6971 
    70     @Orange.misc.deprecated_keywords({"aprioriDist": "apriori_dist"}) 
     72    @deprecated_keywords({"aprioriDist": "apriori_dist"}) 
    7173    def __call__(self, attr, data, apriori_dist=None, weightID=None): 
    7274        """Score the given feature. 
    7375 
    7476        :param attr: feature to score 
    75         :type attr: Orange.feature.Descriptor 
     77        :type attr: :obj:`~Orange.feature.Descriptor` 
    7678 
    7779        :param data: a data table used to score features 
    78         :type data: Orange.data.table 
     80        :type data: :obj:`~Orange.data.Table` 
    7981 
    8082        :param apriori_dist:  
     
    8284         
    8385        :param weightID: meta feature used to weight individual data instances 
    84         :type weightID: Orange.feature.Descriptor 
     86        :type weightID: :obj:`~Orange.feature.Descriptor` 
    8587 
    8688        """ 
    8789        import numpy 
    88         from orngContingency import Entropy 
     90        from orngContingency import Entropy #TODO: Move to new hierarchy 
    8991        if attr in data.domain:  # if we receive attr as string we have to convert to variable 
    9092            attr = data.domain[attr] 
    91         attrClassCont = orange.ContingencyAttrClass(attr, data) 
     93        attrClassCont = contingency.VarClass(attr, data) 
    9294        dist = [] 
    9395        for vals in attrClassCont.values(): 
     
    116118    """ 
    117119 
    118     @Orange.misc.deprecated_keywords({"aprioriDist": "apriori_dist"}) 
     120    @deprecated_keywords({"aprioriDist": "apriori_dist"}) 
    119121    def __new__(cls, attr=None, data=None, apriori_dist=None, weightID=None): 
    120122        self = Score.__new__(cls) 
    121         if attr != None and data != None: 
     123        if attr is not None and data is not None: 
    122124            #self.__init__(**argkw) 
    123125            return self.__call__(attr, data, apriori_dist, weightID) 
     
    125127            return self 
    126128 
    127     @Orange.misc.deprecated_keywords({"aprioriDist": "apriori_dist"}) 
     129    @deprecated_keywords({"aprioriDist": "apriori_dist"}) 
    128130    def __call__(self, attr, data, apriori_dist=None, weightID=None): 
    129131        """Score the given feature. 
    130132 
    131133        :param attr: feature to score 
    132         :type attr: Orange.feature.Descriptor 
     134        :type attr: :obj:`~Orange.feature.Descriptor` 
    133135 
    134136        :param data: a data table used to score the feature 
    135         :type data: Orange.data.table 
     137        :type data: :obj:`~Orange.data.Table` 
    136138 
    137139        :param apriori_dist:  
     
    139141         
    140142        :param weightID: meta feature used to weight individual data instances 
    141         :type weightID: Orange.feature.Descriptor 
     143        :type weightID: :obj:`~Orange.feature.Descriptor` 
    142144 
    143145        """ 
    144         attrClassCont = orange.ContingencyAttrClass(attr, data) 
    145         classDist = orange.Distribution(data.domain.classVar, data).values() 
     146        attrClassCont = contingency.VarClass(attr, data) 
     147        classDist = distribution.Distribution(data.domain.classVar, data).values() 
    146148        nCls = len(classDist) 
    147149        nEx = len(data) 
     
    177179 
    178180 
    179 @Orange.misc.deprecated_keywords({"attrList": "attr_list", "attrMeasure": "attr_score", "removeUnusedValues": "remove_unused_values"}) 
     181@deprecated_keywords({"attrList": "attr_list", "attrMeasure": "attr_score", "removeUnusedValues": "remove_unused_values"}) 
    180182def merge_values(data, attr_list, attr_score, remove_unused_values = 1): 
    181183    import orngCI 
     
    183185    newData = data.select(attr_list + [data.domain.class_var]) 
    184186    newAttr = orngCI.FeatureByCartesianProduct(newData, attr_list)[0] 
    185     dist = orange.Distribution(newAttr, newData) 
     187    dist = distribution.Distribution(newAttr, newData) 
    186188    activeValues = [] 
    187189    for i in range(len(newAttr.values)): 
     
    213215        return newAttr 
    214216 
    215     reducedAttr = orange.EnumVariable(newAttr.name, values = [newAttr.values[i] for i in activeValues]) 
     217    reducedAttr = feature.Discrete.EnumVariable(newAttr.name, values = [newAttr.values[i] for i in activeValues]) 
    216218    reducedAttr.get_value_from = newAttr.get_value_from 
    217219    reducedAttr.get_value_from.class_var = reducedAttr 
     
    220222###### 
    221223# from orngFSS 
    222 @Orange.misc.deprecated_keywords({"measure": "score"}) 
     224@deprecated_keywords({"measure": "score"}) 
    223225def score_all(data, score=Relief(k=20, m=50)): 
    224226    """Assess the quality of features using the given measure and return 
     
    226228 
    227229    :param data: data table should include a discrete class. 
    228     :type data: :obj:`Orange.data.Table` 
     230    :type data: :obj:`~Orange.data.Table` 
    229231    :param score:  feature scoring function. Derived from 
    230232      :obj:`~Orange.feature.scoring.Score`. Defaults to  
    231233      :obj:`~Orange.feature.scoring.Relief` with k=20 and m=50. 
    232     :type measure: :obj:`~Orange.feature.scoring.Score`  
    233     :rtype: :obj:`list`; a sorted (by descending score) list of 
    234       tuples (feature name, score) 
     234    :type score: :obj:`~Orange.feature.scoring.Score` 
     235    :rtype: :obj:`list`; a sorted list of tuples (feature name, score) 
    235236 
    236237    """ 
Note: See TracChangeset for help on using the changeset viewer.