Changeset 10268:c57ea0143d21 in orange


Ignore:
Timestamp:
02/17/12 00:28:11 (2 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Message:

Added FindNearest_BruteForce.instances to _aliases.txt

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/Orange.classification.knn.rst

    r10266 r10268  
    3232    .. attribute:: distance_constructor 
    3333 
    34         component that constructs the object for measuring distances between 
     34        Component that constructs the object for measuring distances between 
    3535        instances. Defaults to :class:`~Orange.distance.Euclidean`. 
    3636 
    3737    .. attribute:: weight_id 
    3838     
    39         id of meta attribute with instance weights 
     39        Id of meta attribute with instance weights. 
    4040 
    4141    .. attribute:: rank_weight 
    4242 
    43         Enables weighting by ranks (default: :obj:`true`) 
     43        If ``True`` (default), neighbours are weighted according to 
     44        their order and not their (normalized) distances to the 
     45        instance that is being classified. 
    4446 
    4547    .. method:: __call__(data) 
    4648 
    47         Return a learned :class:`~kNNClassifier`. Learning consists of 
    48         constructing a distance measure and passing it to the classifier 
    49         along with :obj:`instances` and all attributes. 
     49        Return a :class:`~kNNClassifier`. Learning consists of 
     50        constructing a distance measure and passing it to the 
     51        classifier along with :obj:`instances` and attributes (:obj:`k`, 
     52        :obj:`rank_weight` and :obj:`weight_id`). 
    5053 
    5154        :param instances: training instances 
     
    7073              tuple with both 
    7174         
    72     .. method:: find_nearest(instance) 
    73      
    74     A component which finds the nearest neighbors of a given instance. 
    75          
    76     :param instance: given instance 
    77     :type instance: :class:`~Orange.data.Instance` 
    78          
    79     :rtype: :class:`Orange.data.Instance` 
    80      
     75    .. attribute:: find_nearest 
     76     
     77        A callable component that finds the nearest :obj:`k` neighbors 
     78        of the given instance. 
     79         
     80        :param instance: given instance 
     81        :type instance: :class:`~Orange.data.Instance` 
     82        :rtype: :class:`Orange.data.Instance` 
    8183     
    8284    .. attribute:: k 
     
    8587        the square root of the number of examples is used. 
    8688     
     89    .. attribute:: weight_id 
     90     
     91        Id of meta attribute with instance weights. 
     92 
    8793    .. attribute:: rank_weight 
    88      
    89         Enables weighting by rank (default: :obj:`true`). 
    90      
    91     .. attribute:: weight_id 
    92      
    93         ID of meta attribute with weights of examples 
    94      
     94 
     95        If ``True`` (default), neighbours are weighted according to 
     96        their order and not their (normalized) distances to the 
     97        instance that is being classified. 
     98 
    9599    .. attribute:: n_examples 
    96100     
    97         The number of learning instances. It is used to compute the number of  
     101        The number of learning instances, used to compute the number of  
    98102        neighbors if the value of :attr:`kNNClassifier.k` is zero. 
    99103 
    100 When called to classify an instance, the classifier first calls  
    101 :meth:`kNNClassifier.find_nearest`  
    102 to retrieve a list with :attr:`kNNClassifier.k` nearest neighbors. The 
    103 component :meth:`kNNClassifier.find_nearest` has  
    104 a stored table of instances (those that have been passed to the learner)  
    105 together with their weights. If instances are weighted (non-zero  
    106 :obj:`weight_ID`), weights are considered when counting the neighbors. 
    107  
    108 If :meth:`kNNClassifier.find_nearest` returns only one neighbor  
    109 (this is the case if :obj:`k=1`), :class:`kNNClassifier` returns the 
     104When called to classify instance ``inst``, the classifier first calls 
     105:obj:`kNNClassifier.find_nearest(inst)` to retrieve a list with 
     106:attr:`kNNClassifier.k` nearest neighbors. The component 
     107:meth:`kNNClassifier.find_nearest` has a stored table of training 
     108instances together with their weights. If instances are weighted 
     109(non-zero :obj:`weight_id`), weights are considered when counting the 
     110neighbors. 
     111 
     112If :meth:`kNNClassifier.find_nearest` returns only one neighbor (this 
     113is the case if :obj:`k=1`), :class:`kNNClassifier` returns the 
    110114neighbor's class. 
    111115 
    112 Otherwise, the retrieved neighbors vote about the class prediction 
    113 (or probability of classes). Voting has double weights. As first, if 
    114 instances are weighted, their weights are respected. Secondly, nearer 
    115 neighbors have a greater impact on the prediction; the weight of instance 
    116 is computed as exp(-t:sup:`2`/s:sup:`2`), where the meaning of t depends 
    117 on the setting of :obj:`rank_weight`. 
    118  
    119 * if :obj:`rank_weight` is :obj:`false`, :obj:`t` is the distance from the 
     116Otherwise, the retrieved neighbors vote for the class prediction or 
     117probability of classes. Voting can be a product of two weights: 
     118weights of training instances, if they are given, and weights that 
     119reflect the distance from ``inst``. Nearer neighbors have a greater 
     120impact on the prediction: the weight is computed as 
     121exp(-t:sup:`2`/s:sup:`2`), where the meaning of `t` depends on the 
     122setting of :obj:`rank_weight`. 
     123 
     124* if :obj:`rank_weight` is :obj:`False`, :obj:`t` is the distance from the 
    120125  instance being classified 
    121 * if :obj:`rank_weight` is :obj:`true`, neighbors are ordered and :obj:`t` 
     126* if :obj:`rank_weight` is :obj:`True`, neighbors are ordered and :obj:`t` 
    122127  is the position of the neighbor on the list (a rank) 
    123128 
    124  
    125 In both cases, :obj:`s` is chosen so that the impact of the farthest instance 
    126 is 0.001. 
     129In both cases, :obj:`s` is chosen so that the weight of the farthest 
     130instance is 0.001. 
    127131 
    128132Weighting gives the classifier a certain insensitivity to the number of 
    129133neighbors used, making it possible to use large :obj:`k`'s. 
    130134 
    131 The classifier can treat continuous and discrete features, and can even 
     135The classifier can use continuous and discrete features, and can even 
    132136distinguish between ordinal and nominal features. See information on 
    133137distance measuring for details. 
     
    151155    Iris-setosa Iris-setosa 
    152156 
    153 The secret to kNN's success is that the instances in the iris data set appear in 
    154 three well separated clusters. The classifier's accuracy will remain 
    155 excellent even with a very large or very small number of neighbors. 
    156  
    157 As many experiments have shown, a selection of instances of distance measures 
    158 has neither a greater nor more predictable effect on the performance of kNN 
    159 classifiers. Therefore there is not much point in changing the default. If you 
    160 decide to do so, the distance_constructor must be set to an instance 
    161 of one of the classes for distance measuring. This can be seen in the following 
    162 part of (:download:`knnlearner.py <code/knnlearner.py>`): 
     157The choice of metric usually has not greater impact on the performance 
     158of kNN classifiers, so default should work fine. To change it, 
     159distance_constructor must be set to an instance of one of the classes 
     160for distance measuring. 
    163161 
    164162.. literalinclude:: code/knnExample2.py 
    165  
    166 The output of this code is:: 
    167  
    168     Iris-virginica Iris-versicolor 
    169     Iris-setosa Iris-setosa 
    170     Iris-versicolor Iris-versicolor 
    171     Iris-setosa Iris-setosa 
    172     Iris-setosa Iris-setosa 
    173  
    174 The result is still perfect. 
     163    :lines: 4-7 
    175164 
    176165.. index: fnn 
  • source/orange/_aliases.txt

    r10052 r10268  
    8181ValueFilter 
    8282accept_special acceptSpecial 
     83 
     84FindNearest_BruteForce 
     85instances examples 
Note: See TracChangeset for help on using the changeset viewer.