Changeset 7585:2e5c9bc0dc57 in orange
 Timestamp:
 02/05/11 00:04:13 (3 years ago)
 Branch:
 default
 Convert:
 fb4a3dfe2cedc2960f605dd2f85c92ccf6317e8a
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/classification/knn.py
r7402 r7585 3 3 .. index: 4 4 single: classification; knearest neighbors (kNN) 5 6 The module includes implementation of `nearest neighbors algorithm <http://en.wikipedia.org/wiki/Knearest_neighbor_algorithm>`_ and classes 5 6 ******************* 7 knearest neighbors 8 ******************* 9 10 The module includes implementation of `nearest neighbors 11 algorithm <http://en.wikipedia.org/wiki/Knearest_neighbor_algorithm>`_ and classes 7 12 for finding nearest instances according to chosen distance metrics. 8 13 9 ============================ 10 kNearest Neighbor Algorithm 14 knearest neighbor algorithm 11 15 ============================ 12 16 … … 45 49 .. attribute:: k 46 50 47 Number of neighbo urs. If set to 0 (which is also the default value),51 Number of neighbors. If set to 0 (which is also the default value), 48 52 the square root of the number of instances is used. 49 53 … … 83 87 .. method:: findNearest(instance) 84 88 85 A component that finds nearest neighbo urs of a given instance.89 A component that finds nearest neighbors of a given instance. 86 90 87 91 :param instance: given instance … … 93 97 .. attribute:: k 94 98 95 Number of neighbo urs. If set to 0 (which is also the default value),99 Number of neighbors. If set to 0 (which is also the default value), 96 100 the square root of the number of examples is used. 97 101 … … 111 115 When called to classify an instance, the classifier first calls 112 116 :meth:`kNNClassifier.findNearest` 113 to retrieve a list with :attr:`kNNClassifier.k` nearest neighbo urs. The117 to retrieve a list with :attr:`kNNClassifier.k` nearest neighbors. The 114 118 component :meth:`kNNClassifier.findNearest` has 115 119 a stored table of instances (those that have been passed to the learner) 116 120 together with their weights. If instances are weighted (nonzero 117 :obj:`weightID`), weights are considered when counting the neighbo urs.118 119 If :meth:`kNNClassifier.findNearest` returns only one neighbo ur121 :obj:`weightID`), weights are considered when counting the neighbors. 122 123 If :meth:`kNNClassifier.findNearest` returns only one neighbor 120 124 (this is the case if :obj:`k=1`), :class:`kNNClassifier` returns the 121 125 neighbour's class. … … 130 134 * if :obj:`rankWeight` is :obj:`false`, :obj:`t` is a distance from the 131 135 instance being classified 132 * if :obj:`rankWeight` is :obj:`true`, neighbo urs are ordered and :obj:`t`133 is the position of the neighbo ur on the list (a rank)136 * if :obj:`rankWeight` is :obj:`true`, neighbors are ordered and :obj:`t` 137 is the position of the neighbor on the list (a rank) 134 138 135 139 … … 138 142 139 143 Weighting gives the classifier certain insensitivity to the number of 140 neighbo urs used, making it possible to use large :obj:`k`'s.144 neighbors used, making it possible to use large :obj:`k`'s. 141 145 142 146 The classifier can treat continuous and discrete features, and can even … … 145 149 146 150 Examples 147 ======== 148 149 We will test the learner on 'iris' data set. We shall split it onto train151  152 153 We will test the learner on 'iris' data set. We shall split it onto train 150 154 (80%) and test (20%) sets, learn on training instances and test on five 151 155 randomly selected test instances, in part of … … 162 166 Irissetosa Irissetosa 163 167 164 The secret of kNN's success is that the instances in iris data set appear in165 three well separated clusters. The classifier's accurac cy will remain166 excellent even with very large or small number of neighbo urs.168 The secret of kNN's success is that the instances in iris data set appear in 169 three well separated clusters. The classifier's accuracy will remain 170 excellent even with very large or small number of neighbors. 167 171 168 172 As many experiments have shown, a selection of instances distance measure … … 190 194 .. index: fnn 191 195 192 ========================== 193 Finding Nearest Neighbours194 ========================= =195 196 Orange provides classes for finding the nearest neighbo urs of the given196 197 Finding nearest neighbors 198 ========================= 199 200 Orange provides classes for finding the nearest neighbors of the given 197 201 reference instance. While we might add some smarter classes in future, we 198 now have only two  abstract classes that defines the general behavio ur of199 neighbo ur searching classes, and classes that implement brute force search.202 now have only two  abstract classes that defines the general behavior of 203 neighbor searching classes, and classes that implement brute force search. 200 204 201 205 As usually in Orange, there is a pair of classes: a class that does the work … … 283 287 :rtype: :class:`FindNearest` 284 288 285 Example 286 ======= 289 Examples 290  287 291 288 292 The following script (`knnInstanceDistance.py`_, uses `lenses.tab`_) 289 293 shows how to find the five nearest neighbours of the first instance 290 294 in the lenses dataset. 291 292 293 295 294 296 .. literalinclude:: code/knnInstanceDistance.py
Note: See TracChangeset
for help on using the changeset viewer.