Changeset 10056:da9c4379ea5a in orange


Ignore:
Timestamp:
02/08/12 10:42:16 (2 years ago)
Author:
gregorr
Branch:
default
rebase_source:
f4ed01e991597776f4c84cd4fc315b7eca7c7feb
Message:

Moved CostMatrix (orange.CostMatrix -> Orange.misc.CostMatrix) and documentation updated.

Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • Orange/fixes/fix_changed_names.py

    r10032 r10056  
    7171           "orange.MeasureAttribute_info": "Orange.feature.scoring.InfoGain", 
    7272           "orange.MeasureAttribute_gini": "Orange.feature.scoring.Gini", 
     73            
     74           "orange.CostMatrix" : "Orange.misc.CostMatrix", 
    7375 
    7476           "orange.MeasureAttribute_relevance": "Orange.feature.scoring.Relevance", 
  • Orange/misc/__init__.py

    r10055 r10056  
    44Module Orange.misc contains common functions and classes which are used in other modules. 
    55 
     6.. index: CostMatrix 
     7 
     8----------------------- 
     9CostMatrix 
     10----------------------- 
     11 
     12CostMatrix is an object that stores costs of (mis)classifications. Costs can be either negative or positive. 
     13 
     14.. class:: CostMatrix 
     15 
     16    .. attribute:: classVar  
     17         
     18        The (class) attribute to which the matrix applies. This can also be None. 
     19         
     20    .. attribute:: dimension (read only) 
     21     
     22        Matrix dimension, ie. number of classes. 
     23         
     24    .. method:: CostMatrix(dimension[, default cost]) 
     25     
     26        Constructs a matrix of the given size and initializes it with the default 
     27        cost (1, if not given). All elements of the matrix are assigned the given 
     28        cost, except for the diagonal that have the default cost of 0. 
     29        (Diagonal elements represent correct classifications and these usually 
     30        have no price; you can, however, change this.) 
     31         
     32        .. literalinclude:: code/CostMatrix.py 
     33            :lines: 1-8 
     34         
     35        This initializes the matrix and print it out: 
     36         
     37        .. literalinclude:: code/CostMatrix.res 
     38            :lines: 1-3 
     39     
     40    .. method:: CostMatrix(class descriptor[, default cost]) 
     41     
     42        Similar as above, except that classVar is also set to the given descriptor. 
     43        The number of values of the given attribute (which must be discrete) is used 
     44        for dimension. 
     45         
     46        .. literalinclude:: code/CostMatrix.py 
     47            :lines: 10-11 
     48             
     49        This constructs a matrix similar to the one above (the class attribute in iris 
     50        domain is three-valued) except that the matrix contains 2s instead of 1s. 
     51         
     52    .. method:: CostMatrix([attribute descriptor, ]matrix) 
     53     
     54        Initializes the matrix with the elements given as a sequence of sequences (you 
     55        can mix lists and tuples if you find it funny). Each subsequence represents a row. 
     56         
     57        .. literalinclude:: code/CostMatrix.py 
     58            :lines: 13 
     59 
     60        If you print this matrix out, will it look like this: 
     61         
     62        .. literalinclude:: code/CostMatrix.res 
     63            :lines: 5-7 
     64             
     65    .. method:: setcost(predicted value, correct value, cost) 
     66     
     67        Set the misclassification cost. The matrix above could be constructed by first 
     68        initializing it with 2s and then changing the prices for virginica's into 1s. 
     69         
     70        .. literalinclude:: code/CostMatrix.py 
     71            :lines: 15-17 
     72             
     73    .. method:: getcost(predicted value, correct value) 
     74     
     75        Returns the cost of prediction. Values must be integer indices; if classVar is 
     76        set, you can also use symbolic values (strings). Note that there's no way to 
     77        change the size of the matrix. Size is set at construction and does not change. 
     78        For the final example, we shall compute the profits of knowing attribute values 
     79        in the dataset lenses with the same cost-matrix as printed above. 
     80         
     81        .. literalinclude:: code/CostMatrix.py 
     82            :lines: 19-23 
     83             
     84        As the script shows, you don't have to (and usually won't) call the constructor 
     85        explicitly. Instead, you will set the corresponding field (in our case meas.cost) 
     86        to a matrix and let Orange convert it to CostMatrix automatically. Funny as it 
     87        might look, but since Orange uses constructor to perform such conversion, even 
     88        the above statement is correct (although the cost matrix is rather dull, 
     89        with 0s on the diagonal and 1s around):             
     90             
     91        .. literalinclude:: code/CostMatrix.py 
     92            :lines: 25 
     93                 
    694.. index: SymMatrix 
    795 
Note: See TracChangeset for help on using the changeset viewer.