knn Module

K-nearest neighbours classification algorithm.

@author: drusk

class pml.supervised.knn.Knn(training_set, k=5)[source]

K-Nearest Neighbours classifier.

This algorithm classifies samples based on the ‘k’ closest training examples in the feature space. The sample’s class is predicted through a majority vote of its neighbours.

In the case of a tie, the distances to each tied class are summed amongst the neighbours. The class with the minimum distance to the sample is selected to break the tie.

This is an example of a ‘lazy learning’ algorithm where all computation is deferred until classification.

__init__(training_set, k=5)[source]

Constructs a new Knn classifier.

Args:
training_set:
A labelled DataSet object used to train the classifier.
k:
The number of nearest neighbours to consider when voting for a sample’s class. Must be a positive integer, preferably small. Default value is 5.
Raises:
UnlabelledDataSetError if the training set is not labelled.

Project Versions

Previous topic

info_theory Module

Next topic

loader Module

This Page