Package mvpa :: Package clfs :: Module knn :: Class kNN
[hide private]
[frames] | no frames]

Class kNN

source code


k-nearest-neighbour classifier.

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

Nested Classes [hide private]

Inherited from misc.state.Stateful: __metaclass__

Instance Methods [hide private]
 
__init__(self, k=2, **kwargs)
Cheap initialization.
source code
 
__repr__(self)
Representation of the object
source code
 
__str__(self)
str(x)
source code
 
_train(self, data)
Train the classifier.
source code
 
_predict(self, data)
Predict the class labels for the provided data.
source code
 
getMajorityVote(self, knn_ids)
Simple voting by choosing the majority of class neighbours.
source code
 
getWeightedVote(self, knn_ids)
Vote with classes weighted by the number of samples per class.
source code
 
untrain(self)
Reset trained state
source code

Inherited from base.Classifier: getSensitivityAnalyzer, isTrained, predict, regression, train, train2predict, trained

Inherited from misc.state.Stateful: __getattribute__, __setattr__, reset

Inherited from object: __delattr__, __hash__, __new__, __reduce__, __reduce_ex__

Class Variables [hide private]
  __warned = False
  _clf_internals = ['knn', 'non-linear', 'multiclass']
Describes some specifics about the classifier -- is that it is doing regression for instance....

Inherited from base.Classifier: feature_ids, predicting_time, predictions, retrainable, trained_dataset, trained_labels, training_confusion, training_time, values

Instance Variables [hide private]

Inherited from base.Classifier (private): _regression, _train2predict

Properties [hide private]

Inherited from misc.state.Stateful: descr

Inherited from object: __class__

Method Details [hide private]

__init__(self, k=2, **kwargs)
(Constructor)

source code 
Cheap initialization.
Parameters:
  • k - number of nearest neighbours to be used for voting
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 
Representation of the object
Overrides: object.__repr__

__str__(self)
(Informal representation operator)

source code 
str(x)
Overrides: object.__str__
(inherited documentation)

_train(self, data)

source code 

Train the classifier.

For kNN it is degenerate -- just stores the data.

Overrides: base.Classifier._train

_predict(self, data)

source code 

Predict the class labels for the provided data.

Returns a list of class labels (one for each data sample).

Overrides: base.Classifier._predict

untrain(self)

source code 
Reset trained state
Overrides: base.Classifier.untrain