Package QSTK :: Package qstklearn :: Module kdtknn :: Class kdtknn
[hide private]
[frames] | no frames]

Class kdtknn

source code

object --+
         |
        kdtknn

A simple wrapper of scipy.spatial.kdtree.KDTree

Since the scipy KDTree implementation does not allow for incrementally adding data points, the entire KD-tree is rebuilt on the first call to 'query' after a call to 'addEvidence'. For this reason it is more efficient to add training data in batches.

Instance Methods [hide private]
 
__init__(self, k=3, method='mean', leafsize=10)
Basic setup.
source code
 
addEvidence(self, dataX, dataY=None)
Add training data
source code
 
rebuildKDT(self)
Force the internal KDTree to be rebuilt.
source code
 
query(self, points, k=None, method=None)
Classify a set of test points given their k nearest neighbors.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, k=3, method='mean', leafsize=10)
(Constructor)

source code 

Basic setup.

Overrides: object.__init__

addEvidence(self, dataX, dataY=None)

source code 
Parameters:
  • dataX - Data to add, either entire set with classification as last column, or not if the Y data is provided explicitly. Must be same width as previously appended data.
  • dataY - Optional, can be used

    'data' should be a numpy array matching the same dimensions as any data provided in previous calls to addEvidence, with dataY as the training label.

query(self, points, k=None, method=None)

source code 

Classify a set of test points given their k nearest neighbors.

'points' should be a numpy array with each row corresponding to a specific query. Returns the estimated class according to supplied method (currently only 'mode' and 'mean' are supported)