Table Of Contents

Previous topic

mvpa.clfs.kernel

Next topic

mvpa.clfs.lars

This Page

Quick search

mvpa.clfs.knn

k-Nearest-Neighbour classifier.

The comprehensive API documentation for this module, including all technical details, is available in the Epydoc-generated API reference for mvpa.clfs.knn (for developers).

kNN

class mvpa.clfs.knn.kNN(k=2, dfx=<function squared_euclidean_distance at 0x8fa7f7c>, voting='weighted', **kwargs)

Bases: mvpa.clfs.base.Classifier

k-nearest-neighbour classifier.

If enabled, it stores the votes per class in the ‘values’ state after calling predict().

Parameters:
  • k (unsigned integer) – Number of nearest neighbours to be used for voting.
  • dfx (functor) – Function to compute the distances between training and test samples. Default: squared euclidean distance
  • voting (str) – Voting method used to derive predictions from the nearest neighbors. Possible values are ‘majority’ (simple majority of classes determines vote) and ‘weighted’ (votes are weighted according to the relative frequencies of each class in the training data).
  • **kwargs – Additonal arguments are passed to the base class.
getMajorityVote(knn_ids)
Simple voting by choosing the majority of class neighbours.
getWeightedVote(knn_ids)
Vote with classes weighted by the number of samples per class.
untrain()
Reset trained state

See also

Derived classes might provide additional methods via their base classes. Please refer to the list of base classes (if it exists) at the begining of the kNN documentation.

Full API documentation of kNN in module mvpa.clfs.knn.