glassbox.models.neighbors.index._kdtree¶
KDTreeIndex — space-partitioning tree for efficient nearest-neighbor queries.
KDTreeIndex
¶
Bases: BaseIndex
Initialize the KDTreeIndex.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
DistanceMetric
|
The distance metric to use. |
required |
leaf_size
|
int
|
Number of points at which to switch to brute-force. |
30
|
Source code in glassbox/models/neighbors/index/_kdtree.py
build
¶
Build the KD-Tree structure from the training data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Training data, shape (n_samples, n_features). |
required |
Source code in glassbox/models/neighbors/index/_kdtree.py
query
¶
Query the KD-Tree for the k nearest neighbors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Query point(s), shape (n_features,) or (n_queries, n_features). |
required |
k
|
int
|
Number of nearest neighbors to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Indices of the k nearest neighbors. |