# KNeighborsClassifier

### *class* cuml.dask.neighbors.KNeighborsClassifier(, client=None, streams_per_handle=0, verbose=False, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/kneighbors_classifier.py#L24)

Multi-node Multi-GPU K-Nearest Neighbors Classifier Model.

K-Nearest Neighbors Classifier is an instance-based learning technique,
that keeps training samples around for prediction, rather than trying
to learn a generalizable set of model parameters.

* **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.KNeighborsClassifier.fit)(X, y)        | Fit a multi-node multi-GPU K-Nearest Neighbors Classifier index           |
|-------------------------------------------------------------------|---------------------------------------------------------------------------|
| [`predict`](#cuml.dask.neighbors.KNeighborsClassifier.predict)(X)       | Predict labels for a query from previously stored index and index labels. |
| [`predict_proba`](#cuml.dask.neighbors.KNeighborsClassifier.predict_proba)(X) | Provide score by comparing predictions and ground truth.                  |
| [`score`](#cuml.dask.neighbors.KNeighborsClassifier.score)(X, y)      | Predict labels for a query from previously stored index and index labels. |
<!-- !! processed by numpydoc !! -->

#### fit(X, y)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/kneighbors_classifier.py#L53)

Fit a multi-node multi-GPU K-Nearest Neighbors Classifier index

* **Parameters:**
  **X**
  : Index data.
    Acceptable formats: dask CuPy/NumPy/Numba Array

  **y**
  : Index labels data.
    Acceptable formats: dask CuPy/NumPy/Numba Array
* **Returns:**
  **self**

<!-- !! 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 !! -->

#### predict(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/kneighbors_classifier.py#L162)

Predict labels for a query from previously stored index
and index labels.
The process is done in a multi-node multi-GPU fashion.

* **Parameters:**
  **X**
  : Query data.
    Acceptable formats: dask cuDF, dask CuPy/NumPy/Numba Array
* **Returns:**
  **predictions**

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

#### predict_proba(X)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/kneighbors_classifier.py#L302)

Provide score by comparing predictions and ground truth.

* **Parameters:**
  **X**
  : Query data.
    Acceptable formats: dask cuDF, dask CuPy/NumPy/Numba Array
* **Returns:**
  **probabilities**

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

#### score(X, y)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/neighbors/kneighbors_classifier.py#L269)

Predict labels for a query from previously stored index
and index labels.
The process is done in a multi-node multi-GPU fashion.

* **Parameters:**
  **X**
  : Query test data.
    Acceptable formats: dask CuPy/NumPy/Numba Array

  **y**
  : Labels test data.
    Acceptable formats: dask CuPy/NumPy/Numba Array
* **Returns:**
  score

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