Ignore:
Timestamp:
02/05/12 23:18:56 (2 years ago)
Author:
anze <anze.staric@…>
Branch:
default
rebase_source:
258c3d5cd8774f7a034f936c4f93e2eea47890f3
Message:

Updated documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/classification/knn.py

    r9349 r9665  
    88***************************** 
    99 
    10 This module includes implementation of the `nearest neighbors  
    11 algorithm <http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm>`_ and classes 
    12 for finding the nearest instances according to chosen distance metrics. 
    13  
    14 k-nearest neighbor algorithm 
    15 ============================ 
    16  
    17 The nearest neighbors algorithm is one of the most basic,  
     10The `nearest neighbors 
     11algorithm <http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm>`_ is one of the most basic, 
    1812`lazy <http://en.wikipedia.org/wiki/Lazy_learning>`_ machine learning algorithms. 
    1913The learner only needs to store the instances of training data, while the classifier 
    20 does all the work by searching this list for the instances most similar to  
     14does all the work by searching this list for the instances most similar to 
    2115the data instance being classified: 
    2216 
     17 
    2318.. literalinclude:: code/knnExample0.py 
    2419 
    25 .. class:: kNNLearner(k, distanceConstructor, weightID) 
    26  
    27     :param instances: table of instances 
    28     :type instances: Orange.data.Table 
    29      
    30     :param k: number of nearest neighbors used in classification 
    31     :type k: int 
    32      
    33     :param weightID: id of meta attribute with instance weights 
    34     :type weightID: int 
    35      
    36     :rtype: :class:`kNNLearner` 
    37      
     20.. class:: kNNLearner(k, distance_constructor, weight_id) 
     21 
     22    Lazy classifier that stores instances from the training set. Constructor 
     23    parameters set the corresponding attributes. 
     24 
     25    .. attribute:: k 
     26 
     27        number of nearest neighbors used in classification. If set to 0 
     28        (default), the square root of the numbers of instances is used. 
     29 
     30    .. attribute:: distance_constructor 
     31 
     32        component that constructs the object for measuring distances between 
     33        instances. Defaults to :class:`~Orange.distance.instances.EuclideanConstructor`. 
     34 
     35    .. attribute:: weight_id 
     36     
     37        id of meta attribute with instance weights 
     38 
     39    .. attribute:: rank_weight 
     40 
     41        Enables weighting by ranks (default: :obj:`true`) 
     42 
    3843    .. method:: __call__(instances) 
    39          
    40         Return instance of :class:`kNNClassifier` that learns from the 
    41         :obj:`instances`. 
    42          
    43         :param instances: table of instances 
    44         :type instances: Orange.data.Table 
    45          
    46         :rtype: :class:`kNNClassifier` 
    47  
    48  
    49     .. attribute:: k 
    50      
    51         Number of neighbors. If set to 0 (which is also the default value),  
    52         the square root of the number of instances is used. 
    53      
    54     .. attribute:: rank_weight 
    55      
    56         Enables weighting by ranks (default: :obj:`true`) 
    57      
    58     .. attribute:: distance_constructor 
    59      
    60         component that constructs the object for measuring distances between  
    61         instances. 
    62  
    63 kNNLearner first constructs an object for measuring distances between  
    64 instances. distance_constructor is used if given; otherwise, Euclidean  
    65 metrics will be used. :class:`kNNLearner` then constructs an instance of  
    66 :class:`FindNearest_BruteForce`. Together with the ID of the meta feature with  
    67 weights of instances, :attr:`kNNLearner.k` and :attr:`kNNLearner.rank_weight`, 
    68 it is passed to a :class:`kNNClassifier`. 
    69  
    70 .. class:: kNNClassifier(domain, weightID, k, FindNearest, rankWeight, \ 
    71 nExamples) 
     44 
     45        Return a learned :class:`~kNNClassifier`. Learning consists of 
     46        constructing a distance measure and passing it to the classifier 
     47        along with :obj:`instances` and all attributes. 
     48 
     49        :param instances: training instances 
     50        :type instances: :class:`~Orange.data.Table` 
     51 
     52 
     53.. class:: kNNClassifier(domain, weight_id, k, find_nearest, rank_weight, \ 
     54n_examples) 
    7255 
    7356    .. method:: __call__(instance) 
     
    7861        :param return_type: return value and probabilities, only value or only 
    7962                            probabilities 
    80         :type return_type: Orange.classification.Classifier.GetBoth,  
    81                            Orange.classification.Classifier.GetValue, 
    82                            Orange.classification.Classifier.GetProbilities 
    83          
    84         :rtype: :class:`Orange.data.Value`, 
    85                 :class:`Orange.statistics.distribution`, or a tuple with both 
     63        :type return_type: :class:`Orange.classification.Classifier.GetBoth`, 
     64                           :class:`Orange.classification.Classifier.GetValue`, 
     65                           :class:`Orange.classification.Classifier.GetProbabilities` 
     66         
     67        :rtype: :class:`~Orange.data.Value`, 
     68              :class:`~Orange.statistics.distribution.Distribution` or a 
     69              tuple with both 
    8670         
    8771    .. method:: find_nearest(instance) 
     
    9074         
    9175    :param instance: given instance 
    92     :type instance: Orange.data.Instance 
     76    :type instance: :class:`~Orange.data.Instance` 
    9377         
    9478    :rtype: :class:`Orange.data.Instance` 
     
    10488        Enables weighting by rank (default: :obj:`true`). 
    10589     
    106     .. attribute:: weight_ID 
     90    .. attribute:: weight_id 
    10791     
    10892        ID of meta attribute with weights of examples 
     
    193177 
    194178Finding nearest neighbors 
    195 ========================= 
     179------------------------- 
    196180 
    197181Orange provides classes for finding the nearest neighbors of a given 
Note: See TracChangeset for help on using the changeset viewer.