> 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/0.4/developer-guide/api/concrete.ml.sklearn.protocols.md).

# concrete.ml.sklearn.protocols

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

## module `concrete.ml.sklearn.protocols`

Protocols.

Protocols are used to mix type hinting with duck-typing. Indeed we don't always want to have an abstract parent class between all objects. We are more interested in the behavior of such objects. Implementing a Protocol is a way to specify the behavior of objects.

To read more about Protocol please read: <https://peps.python.org/pep-0544>

***

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

### class `Quantizer`

Quantizer Protocol.

To use to type hint a quantizer.

***

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

#### method `dequant`

```python
dequant(X: 'ndarray') → ndarray
```

Dequantize some values.

**Args:**

* **`X`** (numpy.ndarray): Values to dequantize

.. # noqa: DAR202

**Returns:**

* **`numpy.ndarray`**: Dequantized values

***

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

#### method `quant`

```python
quant(values: 'ndarray') → ndarray
```

Quantize some values.

**Args:**

* **`values`** (numpy.ndarray): Values to quantize

.. # noqa: DAR202

**Returns:**

* **`numpy.ndarray`**: The quantized values

***

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

### class `ConcreteBaseEstimatorProtocol`

A Concrete Estimator Protocol.

***

**property onnx\_model**

onnx\_model.

.. # noqa: DAR202

Results: onnx.ModelProto

***

**property quantize\_input**

Quantize input function.

***

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

#### method `compile`

```python
compile(
    X: 'ndarray',
    configuration: 'Optional[Configuration]',
    compilation_artifacts: 'Optional[DebugArtifacts]',
    show_mlir: 'bool',
    use_virtual_lib: 'bool',
    p_error: 'float'
) → Circuit
```

Compiles a model to a FHE Circuit.

**Args:**

* **`X`** (numpy.ndarray): the dequantized dataset
* **`configuration`** (Optional\[Configuration]): the options for compilation
* **`compilation_artifacts`** (Optional\[DebugArtifacts]): artifacts object to fill during compilation
* **`show_mlir`** (bool): whether or not to show MLIR during the compilation
* **`use_virtual_lib`** (bool): whether to compile using the virtual library that allows higher bitwidths
* **`p_error`** (float): probability of error of a PBS

.. # noqa: DAR202

**Returns:**

* **`Circuit`**: the compiled Circuit.

***

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

#### method `fit`

```python
fit(X: 'ndarray', y: 'ndarray', **fit_params) → ConcreteBaseEstimatorProtocol
```

Initialize and fit the module.

**Args:**

* **`X`** : training data By default, you should be able to pass: \* numpy arrays \* torch tensors \* pandas DataFrame or Series
* **`y`** (numpy.ndarray): labels associated with training data
* **`**fit_params`**: additional parameters that can be used during training

.. # noqa: DAR202

**Returns:**

* **`ConcreteBaseEstimatorProtocol`**: the trained estimator

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'ndarray',
    y: 'ndarray',
    *args,
    **kwargs
) → Tuple[ConcreteBaseEstimatorProtocol, BaseEstimator]
```

Fit the quantized estimator and return reference estimator.

This function returns both the quantized estimator (itself), but also a wrapper around the non-quantized trained NN. This is useful in order to compare performance between the quantized and fp32 versions of the classifier

**Args:**

* **`X`** : training data By default, you should be able to pass: \* numpy arrays \* torch tensors \* pandas DataFrame or Series
* **`y`** (numpy.ndarray): labels associated with training data
* **`*args`**: The arguments to pass to the underlying model.
* **`**kwargs`**: The keyword arguments to pass to the underlying model.

.. # noqa: DAR202

**Returns:**

* **`self`**: self fitted
* **`model`**: underlying estimator

***

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

#### method `post_processing`

```python
post_processing(y_preds: 'ndarray') → ndarray
```

Post-process models predictions.

**Args:**

* **`y_preds`** (numpy.ndarray): predicted values by model (clear-quantized)

.. # noqa: DAR202

**Returns:**

* **`numpy.ndarray`**: the post-processed predictions

***

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

### class `ConcreteBaseClassifierProtocol`

Concrete classifier protocol.

***

**property onnx\_model**

onnx\_model.

.. # noqa: DAR202

Results: onnx.ModelProto

***

**property quantize\_input**

Quantize input function.

***

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

#### method `compile`

```python
compile(
    X: 'ndarray',
    configuration: 'Optional[Configuration]',
    compilation_artifacts: 'Optional[DebugArtifacts]',
    show_mlir: 'bool',
    use_virtual_lib: 'bool',
    p_error: 'float'
) → Circuit
```

Compiles a model to a FHE Circuit.

**Args:**

* **`X`** (numpy.ndarray): the dequantized dataset
* **`configuration`** (Optional\[Configuration]): the options for compilation
* **`compilation_artifacts`** (Optional\[DebugArtifacts]): artifacts object to fill during compilation
* **`show_mlir`** (bool): whether or not to show MLIR during the compilation
* **`use_virtual_lib`** (bool): whether to compile using the virtual library that allows higher bitwidths
* **`p_error`** (float): probability of error of a PBS

.. # noqa: DAR202

**Returns:**

* **`Circuit`**: the compiled Circuit.

***

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

#### method `fit`

```python
fit(X: 'ndarray', y: 'ndarray', **fit_params) → ConcreteBaseEstimatorProtocol
```

Initialize and fit the module.

**Args:**

* **`X`** : training data By default, you should be able to pass: \* numpy arrays \* torch tensors \* pandas DataFrame or Series
* **`y`** (numpy.ndarray): labels associated with training data
* **`**fit_params`**: additional parameters that can be used during training

.. # noqa: DAR202

**Returns:**

* **`ConcreteBaseEstimatorProtocol`**: the trained estimator

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'ndarray',
    y: 'ndarray',
    *args,
    **kwargs
) → Tuple[ConcreteBaseEstimatorProtocol, BaseEstimator]
```

Fit the quantized estimator and return reference estimator.

This function returns both the quantized estimator (itself), but also a wrapper around the non-quantized trained NN. This is useful in order to compare performance between the quantized and fp32 versions of the classifier

**Args:**

* **`X`** : training data By default, you should be able to pass: \* numpy arrays \* torch tensors \* pandas DataFrame or Series
* **`y`** (numpy.ndarray): labels associated with training data
* **`*args`**: The arguments to pass to the underlying model.
* **`**kwargs`**: The keyword arguments to pass to the underlying model.

.. # noqa: DAR202

**Returns:**

* **`self`**: self fitted
* **`model`**: underlying estimator

***

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

#### method `post_processing`

```python
post_processing(y_preds: 'ndarray') → ndarray
```

Post-process models predictions.

**Args:**

* **`y_preds`** (numpy.ndarray): predicted values by model (clear-quantized)

.. # noqa: DAR202

**Returns:**

* **`numpy.ndarray`**: the post-processed predictions

***

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

#### method `predict`

```python
predict(X: 'ndarray', execute_in_fhe: 'bool') → ndarray
```

Predicts for each sample the class with highest probability.

**Args:**

* **`X`** (numpy.ndarray): Features
* **`execute_in_fhe`** (bool): Whether the inference should be done in fhe or not.

.. # noqa: DAR202

**Returns:** numpy.ndarray

***

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

#### method `predict_proba`

```python
predict_proba(X: 'ndarray', execute_in_fhe: 'bool') → ndarray
```

Predicts for each sample the probability of each class.

**Args:**

* **`X`** (numpy.ndarray): Features
* **`execute_in_fhe`** (bool): Whether the inference should be done in fhe or not.

.. # noqa: DAR202

**Returns:** numpy.ndarray

***

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

### class `ConcreteBaseRegressorProtocol`

Concrete regressor protocol.

***

**property onnx\_model**

onnx\_model.

.. # noqa: DAR202

Results: onnx.ModelProto

***

**property quantize\_input**

Quantize input function.

***

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

#### method `compile`

```python
compile(
    X: 'ndarray',
    configuration: 'Optional[Configuration]',
    compilation_artifacts: 'Optional[DebugArtifacts]',
    show_mlir: 'bool',
    use_virtual_lib: 'bool',
    p_error: 'float'
) → Circuit
```

Compiles a model to a FHE Circuit.

**Args:**

* **`X`** (numpy.ndarray): the dequantized dataset
* **`configuration`** (Optional\[Configuration]): the options for compilation
* **`compilation_artifacts`** (Optional\[DebugArtifacts]): artifacts object to fill during compilation
* **`show_mlir`** (bool): whether or not to show MLIR during the compilation
* **`use_virtual_lib`** (bool): whether to compile using the virtual library that allows higher bitwidths
* **`p_error`** (float): probability of error of a PBS

.. # noqa: DAR202

**Returns:**

* **`Circuit`**: the compiled Circuit.

***

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

#### method `fit`

```python
fit(X: 'ndarray', y: 'ndarray', **fit_params) → ConcreteBaseEstimatorProtocol
```

Initialize and fit the module.

**Args:**

* **`X`** : training data By default, you should be able to pass: \* numpy arrays \* torch tensors \* pandas DataFrame or Series
* **`y`** (numpy.ndarray): labels associated with training data
* **`**fit_params`**: additional parameters that can be used during training

.. # noqa: DAR202

**Returns:**

* **`ConcreteBaseEstimatorProtocol`**: the trained estimator

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'ndarray',
    y: 'ndarray',
    *args,
    **kwargs
) → Tuple[ConcreteBaseEstimatorProtocol, BaseEstimator]
```

Fit the quantized estimator and return reference estimator.

This function returns both the quantized estimator (itself), but also a wrapper around the non-quantized trained NN. This is useful in order to compare performance between the quantized and fp32 versions of the classifier

**Args:**

* **`X`** : training data By default, you should be able to pass: \* numpy arrays \* torch tensors \* pandas DataFrame or Series
* **`y`** (numpy.ndarray): labels associated with training data
* **`*args`**: The arguments to pass to the underlying model.
* **`**kwargs`**: The keyword arguments to pass to the underlying model.

.. # noqa: DAR202

**Returns:**

* **`self`**: self fitted
* **`model`**: underlying estimator

***

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

#### method `post_processing`

```python
post_processing(y_preds: 'ndarray') → ndarray
```

Post-process models predictions.

**Args:**

* **`y_preds`** (numpy.ndarray): predicted values by model (clear-quantized)

.. # noqa: DAR202

**Returns:**

* **`numpy.ndarray`**: the post-processed predictions

***

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

#### method `predict`

```python
predict(X: 'ndarray', execute_in_fhe: 'bool') → ndarray
```

Predicts for each sample the expected value.

**Args:**

* **`X`** (numpy.ndarray): Features
* **`execute_in_fhe`** (bool): Whether the inference should be done in fhe or not.

.. # noqa: DAR202

**Returns:** numpy.ndarray


---

# 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/0.4/developer-guide/api/concrete.ml.sklearn.protocols.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.
