Changeset 7570:1af826def4fa in orange


Ignore:
Timestamp:
02/04/11 23:11:37 (3 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
e878347f62165a08e3e7fc28098c135a809d3a72
Message:

No more warnings in Orange.statistics.distributions!

File:
1 edited

Legend:

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

    r7542 r7570  
    33Orange has several classes for computing and storing basic statistics about 
    44features, distributions and contingencies. 
    5   
     5 
     6     
    67======================================== 
    78Basic Statistics for Continuous Features 
     
    1011The are two simple classes for computing basic statistics 
    1112for continuous features, such as their minimal and maximal value 
    12 or average: :class:`BasicAttrStat` holds the statistics for a single feature 
    13 and :class:`DomainBasicAttrStat` is a container storing a list of instances of 
     13or average: :class:`BasicStatistics` holds the statistics for a single feature 
     14and :class:`DomainBasicStatistics` is a container storing a list of instances of 
    1415the above class for all features in the domain. 
    1516 
    16 .. class:: BasicAttrStat 
    17  
    18     `BasicAttrStat` computes on-the fly statistics.  
     17.. class:: BasicStatistics 
     18 
     19    `DomainBasicStatistics` computes on-the fly statistics.  
    1920 
    2021    .. attribute:: variable 
     
    3536        Number of instances for which the value was defined 
    3637        (and used in the statistics). If instances were weighted, 
    37         `n` is the sum of weights of those instances. 
     38        ``n`` is the sum of weights of those instances. 
    3839 
    3940    .. attribute:: sum, sum2 
     
    4748            Holds recomputation of the average and standard deviation. 
    4849 
    49     .. method:: add(value[, weight=1.0]) 
    50  
    51         Adds a value to the statistics. Both arguments should be numbers. 
     50    .. method:: add(value[, weight=1]) 
     51     
     52        :param value: Value to be added to the statistics 
     53        :type value: float 
     54        :param weight: Weight assigned to the value 
     55        :type weight: float 
     56 
     57        Adds a value to the statistics. 
    5258 
    5359    .. 
     
    6066    :obj:`sum` and its square to :obj:`sum2`. The weight is added to :obj:`n`. 
    6167 
     68 
    6269    The statistics does not include the median or any other statistics that can be computed on the fly, without remembering the data. Quantiles can be computed 
    6370    by :obj:`ContDistribution`. !!!TODO 
    6471 
    6572    Instances of this class are seldom constructed manually; they are more often 
    66     returned by :obj:`DomainBasicAttrStat` described below. 
    67  
    68 .. class:: DomainBasicAttrStat 
    69  
    70     :param data: A table of instances 
    71     :type data: Orange.data.Table 
    72     :param weight: The id of the meta-attribute with weights 
    73     :type weight: `int` or none 
    74      
    75     Constructor computes the statistics for all continuous features in the 
    76     give data, and puts `None` to the places corresponding to other types of 
    77     features. 
    78  
     73    returned by :obj:`DomainBasicStatistics` described below. 
     74 
     75.. class:: DomainBasicStatistics 
     76 
     77    ``DomainBasicStatistics`` behaves like a ordinary list, except that its 
     78    elements can also be indexed by feature descriptors or feature names. 
     79 
     80    .. method:: __init__(data[, weight=None]) 
     81 
     82        :param data: A table of instances 
     83        :type data: Orange.data.Table 
     84        :param weight: The id of the meta-attribute with weights 
     85        :type weight: `int` or none 
     86         
     87        Constructor computes the statistics for all continuous features in the 
     88        give data, and puts `None` to the places corresponding to other types of 
     89        features. 
     90     
    7991    .. method:: purge() 
    8092     
    81         Removes the `None`'s corresponding to non-continuous features. 
    82      
    83     `DomainBasicAttrStat` behaves like a ordinary list, except that its 
    84     elements can also be indexed by feature descriptors or feature names. 
    85  
    86     .. _distributions-basic-stat: code/distributions-basic-stat.py 
    87     part of `distributions-basic-stat`_ (uses monks-1.tab) 
    88  
     93        Removes the ``None``'s corresponding to non-continuous features. 
     94     
     95    part of `distributions-basic-stat.py`_ (uses monks-1.tab) 
     96     
    8997    .. literalinclude:: code/distributions-basic-stat.py 
    9098        :lines: 1-10 
    9199 
    92     This code prints out:: 
    93  
    94                  feature   min   max   avg 
    95             sepal length 4.300 7.900 5.843 
    96              sepal width 2.000 4.400 3.054 
    97             petal length 1.000 6.900 3.759 
    98              petal width 0.100 2.500 1.199 
    99  
    100  
    101     .. _distributions-basic-stat: code/distributions-basic-stat.py 
     100    Output:: 
     101 
     102             feature   min   max   avg 
     103        sepal length 4.300 7.900 5.843 
     104         sepal width 2.000 4.400 3.054 
     105        petal length 1.000 6.900 3.759 
     106         petal width 0.100 2.500 1.199 
     107 
     108 
    102109    part of `distributions-basic-stat`_ (uses iris.tab) 
    103  
     110     
    104111    .. literalinclude:: code/distributions-basic-stat.py 
    105112        :lines: 11- 
    106113 
    107     This code prints out:: 
     114    Output:: 
    108115 
    109116        5.84333467484  
    110117 
     118.. _distributions-basic-stat: code/distributions-basic-stat.py 
     119.. _distributions-basic-stat.py: code/distributions-basic-stat.py 
    111120 
    112121 
     
    120129 
    121130.. _distributions-contingency: code/distributions-contingency.py 
     131 
    122132part of `distributions-contingency`_ (uses monks-1.tab) 
    123133 
     
    137147is also possible to use features for both, outer and inner variable, so the 
    138148matrix shows distributions of one variable's values given the value of another. 
    139 There is a corresponding hierarchy of classes for handling hierarchies: :obj:`Contingency` is a base class for :obj:`ContingencyAttrAttr` (and 
    140 :obj:`ContingencyClass`; the latter is  
    141  
    142  
    143  
    144 There is a hierarchy of classes with contingencies:: 
    145  
    146     Contingency:: 
    147         ContingencyClass 
    148         ContingencyClassAttr 
    149         ContingencyAttrClass 
    150     ContingencyAttrAttr 
    151  
    152 The base object is Contingency. Derived from it is ContingencyClass 
    153 in which one of the feaure is class; ContingencyClass 
    154 is a base for two classes, ContingencyAttrClass and ContingencyClassAttr, 
    155 the former having class as the inner and the latter as the outer feature. 
    156 Class ContingencyAttrAttr is derived directly from Contingency and represents 
    157 contingency matrices in which none of the feature is the class. 
    158  
    159 The most common used of the above classes is ContingencyAttrClass which 
    160 resembles conditional probabilities of classes given the feature value. 
    161  
    162 Here's what all contingency matrices share in common. 
     149There is a corresponding hierarchy of classes for handling hierarchies: :obj:`Contingency` is a base class for :obj:`ContingencyVarVar` (both variables 
     150are attribtes) and :obj:`ContingencyClass` (one variable is the class). 
     151The latter is the base class for :obj:`ContingencyVarClass` and :obj:`ContingencyClassVar`. 
     152 
     153The most commonly used of the above classes is :obj:`ContingencyVarClass` which 
     154can compute and store conditional probabilities of classes given the feature value. 
    163155 
    164156.. class:: Orange.statistics.distribution.Contingency 
    165157 
    166     The base class is, once for a change, not abstract. Its constructor expects 
    167     two feature descriptors, the first one for the outer and the second for 
    168     the inner feature. It initializes empty distributions and it's up to you 
    169     to fill them. This is, for instance, how to manually reproduce results of 
    170     the script at the top of the page. 
    171  
    172     .. attribute:: outerVariable 
    173  
    174        The outer feature descriptor. In the above case, it is e.  
    175  
    176     .. attribute:: innerVariable 
    177  
    178         The inner feature descriptor. In the above case, it is the class 
     158    .. attribute:: outerVariable (`Orange.data.feature.Feature`_)  
     159 
     160       Descriptor of the outer variable. 
     161 
     162.. _`Orange.data.feature.Feature`: :obj:`Orange.data.feature.Feature` 
     163 
     164    .. attribute:: innerVariable (:class:`Orange.data.feature.Feature`) 
     165 
     166        Descriptor of the inner variable. 
    179167 
    180168    .. attribute:: outerDistribution 
    181169 
    182         The distribution of the outer featue's values - sums of rows. 
    183         In the above case, distribution of e is 
     170        The distribution (`of the outer feature's values - sums of rows. 
     171        In the above case, distribution of ``e`` is 
    184172        <108.000, 108.000, 108.000, 108.000> 
    185173 
     
    264252 
    265253.. _distributions-contingency2: code/distributions-contingency2.py 
     254 
    266255part of `distributions-contingency2`_ (uses monks-1.tab) 
    267256 
     
    370359 
    371360.. _distributions-contingency3.py: code/distributions-contingency3.py 
     361 
    372362part of `distributions-contingency3.py`_ (uses monks-1.tab) 
    373363 
     
    491481 
    492482 
    493 If the class value is '0', than attribute e cannot be '1' (the first value), 
     483If the class value is '0', then attribute e cannot be '1' (the first value), 
    494484but can be anything else, with equal probabilities of 0.333. 
    495485If the class value is '1', e is '1' in exactly half of examples 
     
    509499        This constructor is exactly the same as that of Contingency. 
    510500 
    511     .. method:: ContingencyAttrAttr(outer_variable, inner_variable,  
    512     instances[, weightID]) 
     501    .. method:: ContingencyAttrAttr(outer_variable, inner_variable,  instances[, weightID]) 
    513502 
    514503        Computes the contingency from the given instances. 
     
    531520 
    532521.. _distributions-contingency5: code/distributions-contingency5.py 
     522 
    533523part of `distributions-contingency5`_ (uses bridges.tab) 
    534524 
     
    557547 
    558548 
    559 ================= 
     549==================================== 
    560550Contingencies with Continuous Values 
    561 ================= 
     551==================================== 
    562552 
    563553What happens if one or both features are continuous? 
     
    575565 
    576566.. _distributions-contingency6: code/distributions-contingency6.py 
     567 
    577568part of `distributions-contingency6`_ (uses monks-1.tab) 
    578569 
     
    598589 
    599590.. _distributions-contingency7: code/distributions-contingency7.py 
     591 
    600592part of `distributions-contingency7`_ (uses iris.tab) 
    601593 
     
    611603 
    612604 
    613 ================= 
     605======================================== 
    614606Computing Contingencies for All Features 
    615 ================= 
     607======================================== 
    616608 
    617609Computing contingency matrices requires iteration through instances. 
     
    650642 
    651643.. _distributions-contingency8: code/distributions-contingency8.py 
     644 
    652645part of `distributions-contingency8`_ (uses monks-1.tab) 
    653646 
     
    665658 
    666659.. _distributions-contingency8: code/distributions-contingency8.py 
     660 
    667661part of `distributions-contingency8`_ (uses monks-1.tab) 
    668662 
Note: See TracChangeset for help on using the changeset viewer.