frlearn.neighbours.neighbour_search
.KDTree¶
-
class
frlearn.neighbours.neighbour_search.
KDTree
(*, metric: str = 'manhattan', leaf_size: int = 30, n_jobs: int = 1)[source]¶ Nearest neighbour search with a KD-tree.
- Parameters
- metricstr, default=’manhattan’
The metric through which distances are defined.
- leaf_sizeint, default=30
The leaf size to be used for the KD-tree.
- n_jobsint, default=1
The number of parallel jobs to run for neighbour search. -1 means using all processors.
-
__init__
(self, *, metric: 'str' = 'manhattan', leaf_size: 'int' = 30, n_jobs: 'int' = 1)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
class
Index
(search: frlearn.neighbours.neighbour_search.KDTree, X)[source]¶ -
query
(self, X, k: 'int')[source]¶ Identify the k nearest neighbours for each of the instances in X.
- Parameters
- Xarray shape=(n_instances, n_features, )
Query instances.
- kint
Number of neighbours to return
- Returns
- Iarray shape=(n_instances, k, )
Indices of the k nearest neighbours among the construction instances for each query instance.
- Darray shape=(n_instances, k, )
Distances to the k nearest neighbours among the construction instances for each query instance.
-
-
construct
(self, X) → 'Index'¶ Construct the index based on the data X.
- Parameters
- Xarray shape=(n_instances, n_features, )
Construction instances.
- Returns
- IIndex
Constructed index