Changeset 10049:ac8f022cd899 in orange


Ignore:
Timestamp:
02/08/12 10:17:19 (2 years ago)
Author:
tomazc <tomaz.curk@…>
Branch:
default
rebase_source:
2f9175fbe723907de5d70a410bcfdeb5ea6349a2
Message:

Minor changes to Orange.data.filter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/Orange.data.filter.rst

    r10031 r10049  
    1010********************** 
    1111 
    12 Filters are used to select instances. They see individual instances, 
    13 not the entire table, and are limited to accepting or rejecting instances. 
    14  
    15 General behavior 
    16 ---------------- 
    17  
    18 All filters follow this structure: 
     12Filters are used to select subsets of instances. Consider the following 
     13example, where instances with age="young" from lenses are 
     14selected: 
     15 
     16.. literalinclude:: code/filter.py 
     17    :lines: 58-64 
     18 
     19Outputs:: 
     20 
     21    Young instances 
     22    ['young', 'myope', 'no', 'reduced', 'none'] 
     23    ['young', 'myope', 'no', 'normal', 'soft'] 
     24    ['young', 'myope', 'yes', 'reduced', 'none'] 
     25    ['young', 'myope', 'yes', 'normal', 'hard'] 
     26    ['young', 'hypermetrope', 'no', 'reduced', 'none'] 
     27    ['young', 'hypermetrope', 'no', 'normal', 'soft'] 
     28    ['young', 'hypermetrope', 'yes', 'reduced', 'none'] 
     29    ['young', 'hypermetrope', 'yes', 'normal', 'hard'] 
     30 
     31:obj:`~Orange.data.Domain.features` behaves as a list and provides method 
     32`index`, which is used to retrieve the position of feature `age`. Feature 
     33`age` is also used to construct a :obj:`~Orange.data.Value`. 
     34 
     35Structure 
     36--------- 
     37 
     38Filters see individual instances, not the entire table, 
     39and are limited to accepting or rejecting instances. All filters have this 
     40structure: 
    1941 
    2042.. class:: Filter 
     
    2244    .. attribute:: negate 
    2345 
    24     Inverts filters' decisions. 
     46    Inverts the selection. Defaults to :obj:`False`. 
    2547 
    2648    .. attribute:: domain 
     
    4163    .. method:: selectionVector(table) 
    4264 
    43     Returns a list of booleans of the same length as :obj:`table`, 
     65    Returns a list of :obj:`bool` of the same length as :obj:`table`, 
    4466    denoting which instances are accepted. Equivalent to 
    4567    `[filter(ex) for i in table]`. 
     
    7698of selecting an instance is set to 0.7, the filter accepted five out of ten 
    7799instances. Because the filter only sees individual instances, it cannot be 
    78 accurate in this regard. If exactly 70% of instances are need, then use 
     100accurate in this regard. If exactly 70% of instances are needed then use 
    79101:obj:`~Orange.data.sample.SubsetIndices2`. 
    80102 
     
    90112    data70 = randomfilter(data) 
    91113 
    92 Filtering instances with(out) unknown values 
    93 -------------------------------------------- 
     114Unknown values 
     115-------------- 
    94116 
    95117.. class:: IsDefined 
     
    108130.. class:: HasClass 
    109131 
    110     Selects instances with defined class value. You can use :obj:`negate` to 
    111     invert the selection, as shown in the script below. 
     132    Selects instances with defined class value. You can use 
     133    :obj:`~Orange.data.filter.Filter.negate` to invert the selection, 
     134    as shown in the script below. 
    112135 
    113136    .. attribute:: check 
    114137 
    115     A list of boolean elements specifying which features to check. Each 
     138    A list of :obj:`bool` elements specifying which features to check. Each 
    116139    element corresponds to a feature in the domain. By default, 
    117140    :obj:`check` is :obj:`None`, meaning that all features are checked. The 
    118141    list is initialized to a list of :obj:`True` when the filter's 
    119     :obj:`domain` is set unless the list already exists. You can also set 
    120     :obj:`check` manually, even without setting the :obj:`domain`. The list 
     142    :obj:`~Orange.data.filter.Filter.domain` is set unless the list 
     143    already exists. You can also set 
     144    :obj:`~Orange.data.filter.HasClass.check` manually, 
     145    even without setting the :obj:`~Orange.data.filter.Filter.domain`. The list 
    121146    can be indexed by ordinary integers (for example, 
    122     `check[0]`). If :obj:`domain` is set, you can also address the list by 
    123     feature names or descriptors. 
    124  
    125 After setting the :obj:`domain`, it should not be modified. Changes will 
     147    `check[0]`). If :obj:`~Orange.data.filter.Filter.domain` is set, 
     148    you can also address the list by feature names or descriptors. 
     149 
     150After setting :obj:`~Orange.data.filter.Filter.domain` 
     151the :obj:`~Orange.data.Domain` should not be modified. Changes will 
    126152disrupt the correspondence between the domain features and the 
    127 list :obj:`check`, causing unpredictable behaviour. 
     153list :obj:`~Orange.data.filter.HasClass.check`, causing unpredictable 
     154behaviour. 
    128155 
    129156.. literalinclude:: code/filter.py 
    130157    :lines: 9, 20-55 
    131158 
    132 Filtering instances with(out) a meta value 
    133 ------------------------------------------ 
     159Meta values 
     160----------- 
    134161 
    135162.. class:: HasMeta 
    136163 
    137     This filters out features that don't have (or that *do have*, 
    138     when :obj:`negate`) a meta attribute with the given id.</P> 
     164    Filters out instances that don't have a meta attribute with the given id. 
    139165 
    140166    .. attribute:: id 
     
    157183The corresponding attributes do not need to be registered in the domain. 
    158184 
    159 Filtering by feature values 
    160 --------------------------- 
    161  
    162 Fast filter for single values 
    163 ============================= 
     185Filtering by value 
     186------------------ 
     187 
     188Single values 
     189============= 
    164190 
    165191.. class:: SameValue 
    166192 
    167     This is a fast filter for selecting instances with particular value of 
    168     some features. 
     193    This is a fast filter for selecting instances with particular value of a 
     194    feature. 
    169195 
    170196    .. attribute:: position 
    171197 
    172     Position of the feature in the domain. Mare sure that you index the 
    173     right :obj:`~Orange.data.Domain`. 
     198    Index of feature in the :obj:`~Orange.data.Domain`. Method `index` 
     199    provided by :obj:`~Orange.data.Domain` can be used to retrieve the 
     200    position of a feature. 
    174201 
    175202    .. attribute:: value 
     
    177204    Features's value. 
    178205 
    179 .. literalinclude:: code/filter.py 
    180     :lines: 58-64 
    181  
    182 This script select instances with age="young" from lenses dataset. Setting 
    183 position is somewhat tricky: `data.domain.features` behaves as a list and 
    184 provides method `index`, which we can use to retrieve the position of 
    185 attribute `age`. Feature `age` is also needed to construct a 
    186 :obj:`~Orange.data.Value`. 
    187  
    188 Simple filter for continuous features 
    189 ===================================== 
     206Continuous features 
     207=================== 
    190208 
    191209:obj:`ValueFilter` provides different methods for filtering values of 
     
    202220    :lines: 52, 75-83 
    203221 
    204 Filter for multiple values and features 
    205 ======================================= 
     222Multiple values and features 
     223============================ 
    206224 
    207225:obj:`~Orange.data.filter.Values` performs a similar function as 
     
    213231    .. attribute:: conditions 
    214232 
    215     A list of :obj:`Orange.data.filter.ValueFilterList` that contains 
     233    A list of :obj:`~Orange.data.filter.ValueFilterList` that contains 
    216234    conditions. Elements must be objects of type 
    217235    :obj:`~Orange.data.filter.ValueFilterDiscrete` for discrete and 
    218236    :obj:`~Orange.data.filter.ValueFilterContinuous` for continuous 
    219237    attributes; both are derived from 
    220     :obj:`Orange.data.filter.ValueFilter`. Both have fields :obj:`position` 
    221     denoting the position of the checked attribute (just as in 
    222     :obj:`Orange.data.filter.SameValue`) and 
    223     :obj:`acceptSpecial` that determines whether undefined values are 
    224     accepted (1), rejected (0) or simply ignored (-1, default). 
     238    :obj:`Orange.data.filter.ValueFilter`. 
    225239 
    226240    .. attribute:: conjunction 
     
    231245    accepted. 
    232246 
    233  
    234 :obj:`~Orange.data.filter.ValueFilterDiscrete` has field 
    235 :obj:`values` of type :obj:`~Orange.ValueList` that contains 
    236 objects of type :obj:`~Orange.data.Value` that 
    237 represent the acceptable values. 
    238  
    239 :obj:`~Orange.data.filter.ValueFilterContinous` has fields 
    240 :obj:`~Orange.data.filter.ValueFilterContinous.min` and 
    241 :obj:`~Orange.data.filter.ValueFilterContinous.max` that define 
    242 an interval, and field 
    243 :obj:`~Orange.data.filter.ValueFilterContinous.outside` that tells whether 
    244 values outside or inside interval are accepted. Defaults to :obj:`False`. 
     247.. class:: ValueFilter 
     248 
     249    .. attribute:: position 
     250 
     251    Indicates the posiiton of the checked feature (similar to 
     252    :obj:`Orange.data.filter.SameValue`). 
     253 
     254    .. attribute:: accept_special 
     255 
     256    Determines whether undefined values are accepted (1), 
     257    rejected (0) or simply ignored (-1, default). 
     258 
     259.. class:: ValueFilterDiscrete 
     260 
     261    .. attribute:: values 
     262 
     263    An immutable :obj:`list` that contains objects of type 
     264    :obj:`~Orange.data.Value`, with values to accept. 
     265 
     266.. class:: ValueFilterContinous 
     267 
     268    .. attribute:: min 
     269 
     270    Lower bound of values to consider. 
     271 
     272    .. attribute:: max 
     273 
     274    Upper bound of values to consider. 
     275 
     276    .. attribute:: outside 
     277 
     278    Indicates whether instances outside the interval should be accepted. 
     279    Defaults to :obj:`False`. 
    245280 
    246281.. literalinclude:: code/filter.py 
     
    253288 
    254289The filter is first constructed and assigned a domain. Then both 
    255 conditions are appended to the filter's :obj:`conditions` field. 
    256 Both are of type :obj:`~Orange.data.filter.ValueFilterDiscrete`, 
    257 since the two attributes are discrete. Position of the attribute is obtained 
    258 the same way as for :obj:`~Orange.data.filter.SameValue` described above. 
     290conditions are appended to the filter's 
     291:obj:`~Orange.data.filter.Values.conditions` field. Both are of type 
     292:obj:`~Orange.data.filter.ValueFilterDiscrete`, since the two attributes are 
     293discrete. Position of the attribute is obtained the same way as for 
     294:obj:`~Orange.data.filter.SameValue` described above. 
    259295 
    260296The list of conditions can also be given to a filter constructor. The 
    261297following filter will accept examples whose age is "young" or "presbyopic" 
    262 or who are astigmatic (<CODE>conjunction = 0</CODE>). For contrast from 
     298or who are astigmatic (`conjunction = 0`). For contrast from 
    263299above filter, unknown age is not acceptable (but examples with unknown age 
    264300can still be accepted if they are astigmatic). Meanwhile, 
    265 examples with unknown astigmatism are always accepted.</P> 
     301examples with unknown astigmatism are always accepted. 
    266302 
    267303.. literalinclude:: code/filter.py 
Note: See TracChangeset for help on using the changeset viewer.