Changeset 7452:a78fb83203fb in orange


Ignore:
Timestamp:
02/04/11 13:39:55 (3 years ago)
Author:
lan <lan@…>
Branch:
default
Convert:
bbff1b86a6625bf0f070de2c8c1d1925ed75b633
Message:

Fixed classes DomaninContingency and Contingency.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/probability/distributions.py

    r7416 r7452  
    8787         petal width 0.100 2.500 1.199 
    8888 
    89 Methods 
    90  
    9189.. class:: Orange.probability.distribution.DomainBasicAttrStat 
    9290 
     
    171169resembles conditional probabilities of classes given the feature value. 
    172170 
    173  
    174 ================= 
    175 General Contingency Matrix 
    176 ================= 
    177  
    178171Here's what all contingency matrices share in common. 
    179172 
    180 Attributes 
     173.. class:: Orange.probability.distribution.Contingency 
     174 
     175    The base class is, once for a change, not abstract. Its constructor expects 
     176    two feature descriptors, the first one for the outer and the second for 
     177    the inner feature. It initializes empty distributions and it's up to you 
     178    to fill them. This is, for instance, how to manually reproduce results of 
     179    the script at the top of the page. 
    181180 
    182181    .. attribute:: outerVariable 
     
    208207       
    209208    .. attribute:: varType 
    210      
     209 
    211210        The varType for the outer feature (discrete, continuous...); 
    212211        varType equals outerVariable.varType and outerDistribution.varType. 
     
    250249Other methods 
    251250 
     251.. class:: Orange.probability.distributions.Contingency 
     252 
    252253    .. method:: add(outer_value, inner_value[, weight]) 
    253254 
     
    269270    3 <0.667, 0.333> 
    270271    4 <0.667, 0.333> 
    271  
    272  
    273 ================= 
    274 Contingency 
    275 ================= 
    276  
    277 The base class is, once for a change, not abstract. Its constructor expects 
    278 two feature descriptors, the first one for the outer and the second for 
    279 the inner feature. It initializes empty distributions and it's up to you 
    280 to fill them. This is, for instance, how to manually reproduce results of 
    281 the script at the top of the page. 
    282272 
    283273.. _distributions-contingency2: code/distributions-contingency2.py 
     
    295285and updates innerDistribution and outerDistribution.  
    296286 
    297  
    298 ================= 
    299 ContingencyClass 
    300 ================= 
    301  
    302 ContingencyClass is an abstract base class for contingency matrices 
    303 that contain the class, either as the inner or the outer 
    304 feature. If offers a function for making filing the contingency clearer. 
    305  
    306 After reading through the rest of this page you might ask yourself 
    307 why do we need to separate the classes ContingencyAttrClass, 
    308 ContingencyClassAttr and ContingencyAttrAttr, 
    309 given that the underlying matrix is the same. This is to avoid confusion 
    310 about what is in the inner and the outer variable. 
    311 Contingency matrices are most often used to compute probabilities of conditional 
    312 classes or features. By separating the classes and giving them specialized 
    313 methods for computing the probabilities that are most suitable to compute 
    314 from a particular class, the user (ie, you or the method that gets passed 
    315 the matrix) is relieved from checking what kind of matrix it got, that is, 
    316 where is the class and where's the feature. 
    317  
    318  
    319287.. class:: Orange.probability.distribution.ContingencyClass 
     288 
     289    ContingencyClass is an abstract base class for contingency matrices 
     290    that contain the class, either as the inner or the outer 
     291    feature. If offers a function for making filing the contingency clearer. 
     292 
     293    After reading through the rest of this page you might ask yourself 
     294    why do we need to separate the classes ContingencyAttrClass, 
     295    ContingencyClassAttr and ContingencyAttrAttr, 
     296    given that the underlying matrix is the same. This is to avoid confusion 
     297    about what is in the inner and the outer variable. 
     298    Contingency matrices are most often used to compute probabilities of conditional 
     299    classes or features. By separating the classes and giving them specialized 
     300    methods for computing the probabilities that are most suitable to compute 
     301    from a particular class, the user (ie, you or the method that gets passed 
     302    the matrix) is relieved from checking what kind of matrix it got, that is, 
     303    where is the class and where's the feature. 
     304 
     305 
    320306 
    321307    .. attribute:: classVar (read only) 
     
    337323 
    338324 
    339 ================= 
    340 ContingencyAttrClass 
    341 ================= 
    342  
    343 ContingencyAttrClass is derived from ContingencyClass. 
    344 Here, feature is the outer variable (hence variable=outerVariable) 
    345 and class is the inner (classVar=innerVariable), so this form of 
    346 contingency matrix is suitable for computing the conditional probabilities 
    347 of classes given a value of a feature. 
    348  
    349 Calling add_attrclass(v, c) is here equivalent to calling add(v, c). 
    350 In addition to this, the class supports computation of contingency from instances, 
    351 as you have already seen in the example at the top of this page. 
    352325 
    353326.. class:: Orange.probability.distribution.ContingencyClass 
     327 
     328    ContingencyAttrClass is derived from ContingencyClass. 
     329    Here, feature is the outer variable (hence variable=outerVariable) 
     330    and class is the inner (classVar=innerVariable), so this form of 
     331    contingency matrix is suitable for computing the conditional probabilities 
     332    of classes given a value of a feature. 
     333 
     334    Calling add_attrclass(v, c) is here equivalent to calling add(v, c). 
     335    In addition to this, the class supports computation of contingency from instances, 
     336    as you have already seen in the example at the top of this page. 
     337 
    354338 
    355339    .. method:: ContingencyAttrClass(feature, class_attribute) 
     
    443427 
    444428 
    445 ================= 
    446 ContingencyClassAttr 
    447 ================= 
    448  
    449 ContingencyClassAttr is similar to ContingencyAttrClass except that here 
    450 the class is the outer and the feature the inner variable. 
    451 As a consequence, this form of contingency matrix is suitable 
    452 for computing conditional probabilities of feature values given class. 
    453 Constructor and add_attrclass nevertheless get the arguments 
    454 in the same order as for ContingencyAttrClass, that is, 
    455 feaure first, class second. 
    456  
    457  
    458429.. class:: Orange.probability.distribution.ContingencyClassAttr 
     430 
     431    ContingencyClassAttr is similar to ContingencyAttrClass except that here 
     432    the class is the outer and the feature the inner variable. 
     433    As a consequence, this form of contingency matrix is suitable 
     434    for computing conditional probabilities of feature values given class. 
     435    Constructor and add_attrclass nevertheless get the arguments 
     436    in the same order as for ContingencyAttrClass, that is, 
     437    feaure first, class second. 
     438 
    459439 
    460440    ..method:: ContingencyClassAttr(attribute, class_attribute) 
     
    524504     
    525505 
    526 ================= 
    527 ContingencyAttrAttr 
    528 ================= 
    529  
    530 ContingencyAttrAttr stores contingency matrices in which none 
    531 of the features is the class. This is rather similar to Contingency, 
    532 except that it has an additional constructor and method for getting 
    533 the conditional probabilities. 
    534  
    535506.. class:: Orange.probability.distribution.ContingencyAttrAttr 
     507 
     508    ContingencyAttrAttr stores contingency matrices in which none 
     509    of the features is the class. This is rather similar to Contingency, 
     510    except that it has an additional constructor and method for getting 
     511    the conditional probabilities. 
    536512 
    537513    .. method:: ContingencyAttrAttr(outer_variable, inner_variable) 
     
    655631additional fields and a constructor that computes the contingencies. 
    656632 
    657  
    658 .. attribute:: classIsOuter (read only) 
    659  
    660     Tells whether the class is the outer or the inner featue. 
    661     Effectively, this tells whether the elements of the list 
    662     are ContingencyAttrClass or ContingencyClassAttr. 
    663  
    664 .. attribute:: classes 
    665  
    666     Contains the distribution of class values on the entire dataset. 
    667  
    668 ..method:: DomainContingency(instances[, weightID][, classIsOuter=0|1]) 
     633.. class:: DomainContingency(instances[, weightID][, classIsOuter=0|1]) 
    669634 
    670635    Constructor needs to be given a list of instances. 
     
    673638    It then iterates through instances and computes the contingencies. 
    674639 
    675 ..method:: normalize 
    676  
    677     Calls normalize for each contingency. 
     640    .. attribute:: classIsOuter (read only) 
     641 
     642        Tells whether the class is the outer or the inner featue. 
     643        Effectively, this tells whether the elements of the list 
     644        are ContingencyAttrClass or ContingencyClassAttr. 
     645 
     646    .. attribute:: classes 
     647 
     648        Contains the distribution of class values on the entire dataset. 
     649 
     650    .. method:: normalize 
     651 
     652        Calls normalize for each contingency. 
    678653 
    679654The following script will print the contingencies for features 
     
    691666To compute the distribution of feature values given the class, 
    692667one needs to get a list of ContingencyClassAttr. 
    693  
    694 part of **distributions-contingency8.py** (uses monk1.tab):: 
    695668 
    696669Note that classIsOuter cannot be given as positional argument, 
     
    713686     DistributionList, \ 
    714687     ComputeDomainContingency, \ 
    715      ConditionalProbabilityEstimator, \ 
    716      ConditionalProbabilityEstimator_ByRows, \ 
    717      ConditionalProbabilityEstimator_FromDistribution, \ 
    718      ConditionalProbabilityEstimatorConstructor, \ 
    719      ConditionalProbabilityEstimatorConstructor_ByRows, \ 
    720      ConditionalProbabilityEstimatorConstructor_loess, \ 
    721      ConditionalProbabilityEstimatorList, \ 
    722688     Contingency, \ 
    723689     ContingencyAttrAttr, \ 
Note: See TracChangeset for help on using the changeset viewer.