# NearestNeighbors

### *class* cuml.dask.neighbors.NearestNeighbors(, client=None, streams_per_handle=0, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/nearest_neighbors.py#L20)

Multi-node Multi-GPU NearestNeighbors Model.

* **Parameters:**
  **n_neighbors**
  : Default number of neighbors to query

  **batch_size: int (optional, default 2000000)**
  : Maximum number of query rows processed at once. This parameter can
    greatly affect the throughput of the algorithm. The optimal setting
    of this value will vary for different layouts and index to query
    ratios, but it will require `batch_size * n_features * 4` bytes of
    additional memory on each worker hosting index partitions.

  **verbose**
  : Sets logging level. It must be one of `cuml.common.logger.level_*`.
    See [Verbosity Levels](../../cuml/index.html.md#verbosity-levels) for more info.

### Methods

| [`fit`](#cuml.dask.neighbors.NearestNeighbors.fit)(X)                            | Fit a multi-node multi-GPU Nearest Neighbors index                                         |
|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| [`get_neighbors`](#cuml.dask.neighbors.NearestNeighbors.get_neighbors)(n_neighbors)        | Returns the default n_neighbors, initialized from the constructor, if n_neighbors is None. |
| [`kneighbors`](#cuml.dask.neighbors.NearestNeighbors.kneighbors)([X, n_neighbors, ...]) | Query the distributed nearest neighbors index                                              |
<!-- !! processed by numpydoc !! -->

#### fit(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/nearest_neighbors.py#L43)

Fit a multi-node multi-GPU Nearest Neighbors index

* **Parameters:**
  **X**
* **Returns:**
  self: NearestNeighbors model

<!-- !! processed by numpydoc !! -->

#### get_combined_model()[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/common/base.py#L57)

Return single-GPU model for serialization

* **Returns:**
  **model**
  : yet been trained.

<!-- !! processed by numpydoc !! -->

#### get_neighbors(n_neighbors)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/nearest_neighbors.py#L113)

Returns the default n_neighbors, initialized from the constructor,
if n_neighbors is None.

* **Parameters:**
  **n_neighbors**
  : Number of neighbors
* **Returns:**
  n_neighbors: int
  : Default n_neighbors if parameter n_neighbors is none

<!-- !! processed by numpydoc !! -->

#### kneighbors(X=None, n_neighbors=None, return_distance=True, \_return_futures=False)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/nearest_neighbors.py#L242)

Query the distributed nearest neighbors index

* **Parameters:**
  **X**
  : Vectors to query. If not provided, neighbors of each indexed point
    are returned.

  **n_neighbors**
  : Number of neighbors to query for each row in X. If not provided,
    the n_neighbors on the model are used.

  **return_distance**
  : If false, only indices are returned
* **Returns:**
  **ret**
  : First dask-cuDF DataFrame contains distances, second contains the
    indices.

<!-- !! processed by numpydoc !! -->
