Warning: This documentation is for scikits.learn version 0.7.1. — Latest stable version

Contents

6.5.3. scikits.learn.ball_tree.BallTree

class scikits.learn.ball_tree.BallTree

Ball Tree for fast nearest-neighbor searches :

BallTree(M, leafsize=20)

Parameters :

M : array-like, shape = [N,D]

N is the number of points in the data set, and D is the dimension of the parameter space.

Note: if M is an aligned array of doubles (not

necessarily contiguous) then data will not be copied. Otherwise, an internal copy will be made.

leafsize : positive integer (default = 20)

number of points at which to switch to brute-force

Methods

query(x[, k, return_distance]) query the Ball Tree for the k nearest neighbors
query_ball(x,r,count_only = False) query the Ball Tree for the k nearest neighbors
__init__()

x.__init__(...) initializes x; see help(type(x)) for signature

data

View of data making up the Ball Tree

dim

Dimension of the Ball Tree

query(x, k=1, return_distance=True)
query the Ball Tree for the k nearest neighbors
Parameters :

x : array-like, last dimension self.dim

An array of points to query

k : integer (default = 1)

The number of nearest neighbors to return

return_distance : boolean (default = True)

if True, return a tuple (d,i) if False, return array i

Returns :

i : if return_distance == False

(d,i) : if return_distance == True

d : array of doubles - shape: x.shape[:-1] + (k,)

each entry gives the list of distances to the neighbors of the corresponding point (note that distances are not sorted)

i : array of integers - shape: x.shape[:-1] + (k,)

each entry gives the list of indices of neighbors of the corresponding point (note that neighbors are not sorted)

query_ball(x, r, count_only = False)
query the Ball Tree for the k nearest neighbors
Parameters :

x : array-like, last dimension self.dim

An array of points to query

r : floating-point value

Radius around each point within which all neighbors are returned

count_only : boolean (default = False)

if True, return count of neighbors

for each point

if False, return full list of

neighbors for each point

Returns :

i : array of integers, shape: x.shape[:-1]

if count_only is False each entry gives the list of neighbors of the corresponding point (note that neighbors are not sorted). Otherwise return only the number of neighbors.

size

Number of points in the Ball Tree