> For the complete documentation index, see [llms.txt](https://docs.zama.org/concrete-ml/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/concrete-ml/1.2/developer-guide/api/concrete.ml.sklearn.neighbors.md).

# concrete.ml.sklearn.neighbors.md

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.2.x/src/concrete/ml/sklearn/neighbors.py#L0)

## module `concrete.ml.sklearn.neighbors`

Implement sklearn linear model.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.2.x/src/concrete/ml/sklearn/neighbors.py#L13)

### class `KNeighborsClassifier`

A k-nearest neighbors classifier model with FHE.

**Parameters:**

* `n_bits` (int): Number of bits to quantize the model. The value will be used for quantizing inputs and X\_fit. Default to 3.

For more details on KNeighborsClassifier please refer to the scikit-learn documentation: <https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html>

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.2.x/src/concrete/ml/sklearn/neighbors.py#L27)

#### method `__init__`

```python
__init__(
    n_bits=2,
    n_neighbors=3,
    weights='uniform',
    algorithm='auto',
    leaf_size=30,
    p=2,
    metric='minkowski',
    metric_params=None,
    n_jobs=None
)
```

***

**property fhe\_circuit**

Get the FHE circuit.

The FHE circuit combines computational graph, mlir, client and server into a single object. More information available in Concrete documentation (<https://docs.zama.ai/concrete/getting-started/terminology\\_and\\_structure>) Is None if the model is not fitted.

**Returns:**

* `Circuit`: The FHE circuit.

***

**property is\_compiled**

Indicate if the model is compiled.

**Returns:**

* `bool`: If the model is compiled.

***

**property is\_fitted**

Indicate if the model is fitted.

**Returns:**

* `bool`: If the model is fitted.

***

**property onnx\_model**

Get the ONNX model.

Is None if the model is not fitted.

**Returns:**

* `onnx.ModelProto`: The ONNX model.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.2.x/src/concrete/ml/sklearn/neighbors.py#L64)

#### method `dump_dict`

```python
dump_dict() → Dict[str, Any]
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.2.x/src/concrete/ml/sklearn/neighbors.py#L97)

#### classmethod `load_dict`

```python
load_dict(metadata: Dict)
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.2.x/src/concrete/ml/sklearn/neighbors.py#L130)

#### method `predict_proba`

```python
predict_proba(
    X: Union[ndarray, Tensor, ForwardRef('DataFrame'), List],
    fhe: Union[FheMode, str] = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Predict class probabilities.

**Args:**

* `X` (Data): The input values to predict, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `fhe` (Union\[FheMode, str]): The mode to use for prediction. Can be FheMode.DISABLE for Concrete ML Python inference, FheMode.SIMULATE for FHE simulation and FheMode.EXECUTE for actual FHE execution. Can also be the string representation of any of these values. Default to FheMode.DISABLE.

**Raises:**

* `NotImplementedError`: The method is not implemented for now.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/concrete-ml/1.2/developer-guide/api/concrete.ml.sklearn.neighbors.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
