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

# concrete.ml.sklearn.base.md

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

## module `concrete.ml.sklearn.base`

Base classes for all estimators.

### **Global Variables**

* **OPSET\_VERSION\_FOR\_ONNX\_EXPORT**
* **QNN\_AUTO\_KWARGS**

***

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

### class `BaseEstimator`

Base class for all estimators in Concrete ML.

This class does not inherit from sklearn.base.BaseEstimator as it creates some conflicts with skorch in QuantizedTorchEstimatorMixin's subclasses (more specifically, the `get_params` method is not properly inherited).

**Attributes:**

* `_is_a_public_cml_model` (bool): Private attribute indicating if the class is a public model (as opposed to base or mixin classes).

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

#### method `__init__`

```python
__init__()
```

Initialize the base class with common attributes used in all estimators.

An underscore "\_" is appended to attributes that were created while fitting the model. This is done in order to follow scikit-Learn's standard format. More information available in their documentation: <https://scikit-learn.org/stable/developers/develop.html#:\\~:text=Estimated%20Attributes%C2%B6>

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(
    X: 'Data',
    configuration: 'Optional[Configuration]' = None,
    artifacts: 'Optional[DebugArtifacts]' = None,
    show_mlir: 'bool' = False,
    p_error: 'Optional[float]' = None,
    global_p_error: 'Optional[float]' = None,
    verbose: 'bool' = False
) → Circuit
```

Compile the model.

**Args:**

* `X` (Data): A representative set of input values used for building cryptographic parameters, as a Numpy array, Torch tensor, Pandas DataFrame or List. This is usually the training data-set or s sub-set of it.
* `configuration` (Optional\[Configuration]): Options to use for compilation. Default to None.
* `artifacts` (Optional\[DebugArtifacts]): Artifacts information about the compilation process to store for debugging. Default to None.
* `show_mlir` (bool): Indicate if the MLIR graph should be printed during compilation. Default to False.
* `p_error` (Optional\[float]): Probability of error of a single PBS. A p\_error value cannot be given if a global\_p\_error value is already set. Default to None, which sets this error to a default value.
* `global_p_error` (Optional\[float]): Probability of error of the full circuit. A global\_p\_error value cannot be given if a p\_error value is already set. This feature is not supported during the FHE simulation mode, meaning the probability is currently set to 0. Default to None, which sets this error to a default value.
* `verbose` (bool): Indicate if compilation information should be printed during compilation. Default to False.

**Returns:**

* `Circuit`: The compiled Circuit.

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

De-quantize the output.

This step ensures that the fit method has been called.

**Args:**

* `q_y_preds` (numpy.ndarray): The quantized output values to de-quantize.

**Returns:**

* `numpy.ndarray`: The de-quantized output values.

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

Fit the estimator.

This method trains a scikit-learn estimator, computes its ONNX graph and defines the quantization parameters needed for proper FHE inference.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The fitted estimator.

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

Apply post-processing to the de-quantized predictions.

This post-processing step can include operations such as applying the sigmoid or softmax function for classifiers, or summing an ensemble's outputs. These steps are done in the clear because of current technical constraints. They most likely will be integrated in the FHE computations in the future.

For some simple models such a linear regression, there is no post-processing step but the method is kept to make the API consistent for the client-server API. Other models might need to use attributes stored in `post_processing_params`.

**Args:**

* `y_preds` (numpy.ndarray): The de-quantized predictions to post-process.

**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/1.1.x/src/concrete/ml/sklearn/base.py#L574)

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Predict values for X, in FHE or in the clear.

**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.

**Returns:**

* `np.ndarray`: The predicted values for X.

***

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

#### method `quantize_input`

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

Quantize the input.

This step ensures that the fit method has been called.

**Args:**

* `X` (numpy.ndarray): The input values to quantize.

**Returns:**

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

***

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

### class `BaseClassifier`

Base class for linear and tree-based classifiers in Concrete ML.

This class inherits from BaseEstimator and modifies some of its methods in order to align them with classifier behaviors. This notably include applying a sigmoid/softmax post-processing to the predicted values as well as handling a mapping of classes in case they are not ordered.

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

#### method `__init__`

```python
__init__(*args, **kwargs)
```

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(
    X: 'Data',
    configuration: 'Optional[Configuration]' = None,
    artifacts: 'Optional[DebugArtifacts]' = None,
    show_mlir: 'bool' = False,
    p_error: 'Optional[float]' = None,
    global_p_error: 'Optional[float]' = None,
    verbose: 'bool' = False
) → Circuit
```

Compile the model.

**Args:**

* `X` (Data): A representative set of input values used for building cryptographic parameters, as a Numpy array, Torch tensor, Pandas DataFrame or List. This is usually the training data-set or s sub-set of it.
* `configuration` (Optional\[Configuration]): Options to use for compilation. Default to None.
* `artifacts` (Optional\[DebugArtifacts]): Artifacts information about the compilation process to store for debugging. Default to None.
* `show_mlir` (bool): Indicate if the MLIR graph should be printed during compilation. Default to False.
* `p_error` (Optional\[float]): Probability of error of a single PBS. A p\_error value cannot be given if a global\_p\_error value is already set. Default to None, which sets this error to a default value.
* `global_p_error` (Optional\[float]): Probability of error of the full circuit. A global\_p\_error value cannot be given if a p\_error value is already set. This feature is not supported during the FHE simulation mode, meaning the probability is currently set to 0. Default to None, which sets this error to a default value.
* `verbose` (bool): Indicate if compilation information should be printed during compilation. Default to False.

**Returns:**

* `Circuit`: The compiled Circuit.

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

De-quantize the output.

This step ensures that the fit method has been called.

**Args:**

* `q_y_preds` (numpy.ndarray): The quantized output values to de-quantize.

**Returns:**

* `numpy.ndarray`: The de-quantized output values.

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

***

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

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

***

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

#### method `predict_proba`

```python
predict_proba(
    X: 'Data',
    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.

**Returns:**

* `numpy.ndarray`: The predicted class probabilities.

***

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

#### method `quantize_input`

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

Quantize the input.

This step ensures that the fit method has been called.

**Args:**

* `X` (numpy.ndarray): The input values to quantize.

**Returns:**

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

***

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

### class `QuantizedTorchEstimatorMixin`

Mixin that provides quantization for a torch module and follows the Estimator API.

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

#### method `__init__`

```python
__init__()
```

***

**property base\_module**

Get the Torch module.

**Returns:**

* `SparseQuantNeuralNetwork`: The fitted underlying module.

***

**property fhe\_circuit**

***

**property input\_quantizers**

Get the input quantizers.

**Returns:**

* `List[UniformQuantizer]`: The input quantizers.

***

**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.

***

**property output\_quantizers**

Get the output quantizers.

**Returns:**

* `List[UniformQuantizer]`: The output quantizers.

***

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

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(
    X: 'Data',
    configuration: 'Optional[Configuration]' = None,
    artifacts: 'Optional[DebugArtifacts]' = None,
    show_mlir: 'bool' = False,
    p_error: 'Optional[float]' = None,
    global_p_error: 'Optional[float]' = None,
    verbose: 'bool' = False
) → Circuit
```

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

Fit he estimator.

If the module was already initialized, the module will be re-initialized unless `warm_start` is set to True. In addition to the torch training step, this method performs quantization of the trained Torch model using Quantization Aware Training (QAT).

Values of dtype float64 are not supported and will be casted to float32.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `**fit_parameters`: Keyword arguments to pass to skorch's fit method.

**Returns:** The fitted estimator.

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit the quantized estimator as well as its equivalent float estimator.

This function returns both the quantized estimator (itself) as well as its non-quantized (float) equivalent, which are both trained separately. This method differs from the BaseEstimator's `fit_benchmark` method as QNNs use QAT instead of PTQ. Hence, here, the float model is topologically equivalent as we have less control over the influence of QAT over the weights.

Values of dtype float64 are not supported and will be casted to float32.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. However, skorch does not handle such a parameter and setting it will have no effect. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to skorch's fit method.

**Returns:** The Concrete ML and equivalent skorch fitted estimators.

***

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

#### method `get_params`

```python
get_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is overloaded in order to make sure that auto-computed parameters are not considered when cloning the model (e.g during a GridSearchCV call).

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → Dict
```

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

***

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

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Predict values for X, in FHE or in the clear.

**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.

**Returns:**

* `np.ndarray`: The predicted values for X.

***

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

#### method `prune`

```python
prune(X: 'Data', y: 'Target', n_prune_neurons_percentage: 'float', **fit_params)
```

Prune a copy of this Neural Network model.

This can be used when the number of neurons on the hidden layers is too high. For example, when creating a Neural Network model with `n_hidden_neurons_multiplier` high (3-4), it can be used to speed up the model inference in FHE. Many times, up to 50% of neurons can be pruned without losing accuracy, when using this function to fine-tune an already trained model with good accuracy. This method should be used once good accuracy is obtained.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame Pandas Series or List.
* `n_prune_neurons_percentage` (float): The percentage of neurons to remove. A value of 0 (resp. 1.0) means no (resp. all) neurons will be removed.
* `fit_params`: Additional parameters to pass to the underlying nn.Module's forward method.

**Returns:** A new pruned copy of the Neural Network model.

**Raises:**

* `ValueError`: If the model has not been trained or has already been pruned.

***

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

#### method `quantize_input`

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

***

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

### class `BaseTreeEstimatorMixin`

Mixin class for tree-based estimators.

This class inherits from sklearn.base.BaseEstimator in order to have access to scikit-learn's `get_params` and `set_params` methods.

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

#### method `__init__`

```python
__init__(n_bits: 'int')
```

Initialize the TreeBasedEstimatorMixin.

**Args:**

* `n_bits` (int): The number of bits used for quantization.

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(*args, **kwargs) → Circuit
```

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

***

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

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

***

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

#### method `quantize_input`

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

***

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

### class `BaseTreeRegressorMixin`

Mixin class for tree-based regressors.

This class is used to create a tree-based regressor class that inherits from sklearn.base.RegressorMixin, which essentially gives access to scikit-learn's `score` method for regressors.

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

#### method `__init__`

```python
__init__(n_bits: 'int')
```

Initialize the TreeBasedEstimatorMixin.

**Args:**

* `n_bits` (int): The number of bits used for quantization.

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(*args, **kwargs) → Circuit
```

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

***

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

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

***

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

#### method `quantize_input`

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

***

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

### class `BaseTreeClassifierMixin`

Mixin class for tree-based classifiers.

This class is used to create a tree-based classifier class that inherits from sklearn.base.ClassifierMixin, which essentially gives access to scikit-learn's `score` method for classifiers.

Additionally, this class adjusts some of the tree-based base class's methods in order to make them compliant with classification workflows.

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

#### method `__init__`

```python
__init__(*args, **kwargs)
```

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(*args, **kwargs) → Circuit
```

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

***

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

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

***

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

#### method `predict_proba`

```python
predict_proba(
    X: 'Data',
    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.

**Returns:**

* `numpy.ndarray`: The predicted class probabilities.

***

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

#### method `quantize_input`

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

***

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

### class `SklearnLinearModelMixin`

A Mixin class for sklearn linear models with FHE.

This class inherits from sklearn.base.BaseEstimator in order to have access to scikit-learn's `get_params` and `set_params` methods.

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

#### method `__init__`

```python
__init__(n_bits: 'Union[int, Dict[str, int]]' = 8)
```

Initialize the FHE linear model.

**Args:**

* `n_bits` (int, Dict\[str, int]): Number of bits to quantize the model. If an int is passed for n\_bits, the value will be used for quantizing inputs and weights. If a dict is passed, then it should contain "op\_inputs" and "op\_weights" as keys with corresponding number of quantization bits so that: - op\_inputs : number of bits to quantize the input values - op\_weights: number of bits to quantize the learned parameters Default to 8.

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(
    X: 'Data',
    configuration: 'Optional[Configuration]' = None,
    artifacts: 'Optional[DebugArtifacts]' = None,
    show_mlir: 'bool' = False,
    p_error: 'Optional[float]' = None,
    global_p_error: 'Optional[float]' = None,
    verbose: 'bool' = False
) → Circuit
```

Compile the model.

**Args:**

* `X` (Data): A representative set of input values used for building cryptographic parameters, as a Numpy array, Torch tensor, Pandas DataFrame or List. This is usually the training data-set or s sub-set of it.
* `configuration` (Optional\[Configuration]): Options to use for compilation. Default to None.
* `artifacts` (Optional\[DebugArtifacts]): Artifacts information about the compilation process to store for debugging. Default to None.
* `show_mlir` (bool): Indicate if the MLIR graph should be printed during compilation. Default to False.
* `p_error` (Optional\[float]): Probability of error of a single PBS. A p\_error value cannot be given if a global\_p\_error value is already set. Default to None, which sets this error to a default value.
* `global_p_error` (Optional\[float]): Probability of error of the full circuit. A global\_p\_error value cannot be given if a p\_error value is already set. This feature is not supported during the FHE simulation mode, meaning the probability is currently set to 0. Default to None, which sets this error to a default value.
* `verbose` (bool): Indicate if compilation information should be printed during compilation. Default to False.

**Returns:**

* `Circuit`: The compiled Circuit.

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

Apply post-processing to the de-quantized predictions.

This post-processing step can include operations such as applying the sigmoid or softmax function for classifiers, or summing an ensemble's outputs. These steps are done in the clear because of current technical constraints. They most likely will be integrated in the FHE computations in the future.

For some simple models such a linear regression, there is no post-processing step but the method is kept to make the API consistent for the client-server API. Other models might need to use attributes stored in `post_processing_params`.

**Args:**

* `y_preds` (numpy.ndarray): The de-quantized predictions to post-process.

**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/1.1.x/src/concrete/ml/sklearn/base.py#L574)

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Predict values for X, in FHE or in the clear.

**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.

**Returns:**

* `np.ndarray`: The predicted values for X.

***

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

#### method `quantize_input`

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

***

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

### class `SklearnLinearRegressorMixin`

A Mixin class for sklearn linear regressors with FHE.

This class is used to create a linear regressor class that inherits from sklearn.base.RegressorMixin, which essentially gives access to scikit-learn's `score` method for regressors.

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

#### method `__init__`

```python
__init__(n_bits: 'Union[int, Dict[str, int]]' = 8)
```

Initialize the FHE linear model.

**Args:**

* `n_bits` (int, Dict\[str, int]): Number of bits to quantize the model. If an int is passed for n\_bits, the value will be used for quantizing inputs and weights. If a dict is passed, then it should contain "op\_inputs" and "op\_weights" as keys with corresponding number of quantization bits so that: - op\_inputs : number of bits to quantize the input values - op\_weights: number of bits to quantize the learned parameters Default to 8.

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(
    X: 'Data',
    configuration: 'Optional[Configuration]' = None,
    artifacts: 'Optional[DebugArtifacts]' = None,
    show_mlir: 'bool' = False,
    p_error: 'Optional[float]' = None,
    global_p_error: 'Optional[float]' = None,
    verbose: 'bool' = False
) → Circuit
```

Compile the model.

**Args:**

* `X` (Data): A representative set of input values used for building cryptographic parameters, as a Numpy array, Torch tensor, Pandas DataFrame or List. This is usually the training data-set or s sub-set of it.
* `configuration` (Optional\[Configuration]): Options to use for compilation. Default to None.
* `artifacts` (Optional\[DebugArtifacts]): Artifacts information about the compilation process to store for debugging. Default to None.
* `show_mlir` (bool): Indicate if the MLIR graph should be printed during compilation. Default to False.
* `p_error` (Optional\[float]): Probability of error of a single PBS. A p\_error value cannot be given if a global\_p\_error value is already set. Default to None, which sets this error to a default value.
* `global_p_error` (Optional\[float]): Probability of error of the full circuit. A global\_p\_error value cannot be given if a p\_error value is already set. This feature is not supported during the FHE simulation mode, meaning the probability is currently set to 0. Default to None, which sets this error to a default value.
* `verbose` (bool): Indicate if compilation information should be printed during compilation. Default to False.

**Returns:**

* `Circuit`: The compiled Circuit.

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

Apply post-processing to the de-quantized predictions.

This post-processing step can include operations such as applying the sigmoid or softmax function for classifiers, or summing an ensemble's outputs. These steps are done in the clear because of current technical constraints. They most likely will be integrated in the FHE computations in the future.

For some simple models such a linear regression, there is no post-processing step but the method is kept to make the API consistent for the client-server API. Other models might need to use attributes stored in `post_processing_params`.

**Args:**

* `y_preds` (numpy.ndarray): The de-quantized predictions to post-process.

**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/1.1.x/src/concrete/ml/sklearn/base.py#L574)

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Predict values for X, in FHE or in the clear.

**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.

**Returns:**

* `np.ndarray`: The predicted values for X.

***

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

#### method `quantize_input`

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

***

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

### class `SklearnLinearClassifierMixin`

A Mixin class for sklearn linear classifiers with FHE.

This class is used to create a linear classifier class that inherits from sklearn.base.ClassifierMixin, which essentially gives access to scikit-learn's `score` method for classifiers.

Additionally, this class adjusts some of the tree-based base class's methods in order to make them compliant with classification workflows.

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

#### method `__init__`

```python
__init__(*args, **kwargs)
```

***

**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/developer/terminology\\_and\\_structure#terminology> 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.1.x/src/concrete/ml/sklearn/base.py#L306)

#### method `check_model_is_compiled`

```python
check_model_is_compiled() → None
```

Check if the model is compiled.

**Raises:**

* `AttributeError`: If the model is not compiled.

***

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

#### method `check_model_is_fitted`

```python
check_model_is_fitted() → None
```

Check if the model is fitted.

**Raises:**

* `AttributeError`: If the model is not fitted.

***

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

#### method `compile`

```python
compile(
    X: 'Data',
    configuration: 'Optional[Configuration]' = None,
    artifacts: 'Optional[DebugArtifacts]' = None,
    show_mlir: 'bool' = False,
    p_error: 'Optional[float]' = None,
    global_p_error: 'Optional[float]' = None,
    verbose: 'bool' = False
) → Circuit
```

Compile the model.

**Args:**

* `X` (Data): A representative set of input values used for building cryptographic parameters, as a Numpy array, Torch tensor, Pandas DataFrame or List. This is usually the training data-set or s sub-set of it.
* `configuration` (Optional\[Configuration]): Options to use for compilation. Default to None.
* `artifacts` (Optional\[DebugArtifacts]): Artifacts information about the compilation process to store for debugging. Default to None.
* `show_mlir` (bool): Indicate if the MLIR graph should be printed during compilation. Default to False.
* `p_error` (Optional\[float]): Probability of error of a single PBS. A p\_error value cannot be given if a global\_p\_error value is already set. Default to None, which sets this error to a default value.
* `global_p_error` (Optional\[float]): Probability of error of the full circuit. A global\_p\_error value cannot be given if a p\_error value is already set. This feature is not supported during the FHE simulation mode, meaning the probability is currently set to 0. Default to None, which sets this error to a default value.
* `verbose` (bool): Indicate if compilation information should be printed during compilation. Default to False.

**Returns:**

* `Circuit`: The compiled Circuit.

***

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

#### method `decision_function`

```python
decision_function(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

Predict confidence scores.

**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.

**Returns:**

* `numpy.ndarray`: The predicted confidence scores.

***

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

#### method `dequantize_output`

```python
dequantize_output(q_y_preds: 'ndarray') → ndarray
```

***

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

#### method `dump`

```python
dump(file: 'TextIO') → None
```

Dump itself to a file.

**Args:**

* `file` (TextIO): The file to dump the serialized object into.

***

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

#### method `dump_dict`

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

Dump the object as a dict.

**Returns:**

* `Dict[str, Any]`: Dict of serialized objects.

***

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

#### method `dumps`

```python
dumps() → str
```

Dump itself to a string.

**Returns:**

* `metadata` (str): String of the serialized object.

***

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

#### method `fit`

```python
fit(X: 'Data', y: 'Target', **fit_parameters)
```

***

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

#### method `fit_benchmark`

```python
fit_benchmark(
    X: 'Data',
    y: 'Target',
    random_state: 'Optional[int]' = None,
    **fit_parameters
)
```

Fit both the Concrete ML and its equivalent float estimators.

**Args:**

* `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List.
* `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List.
* `random_state` (Optional\[int]): The random state to use when fitting. Defaults to None.
* `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method.

**Returns:** The Concrete ML and float equivalent fitted estimators.

***

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

#### method `get_sklearn_params`

```python
get_sklearn_params(deep: 'bool' = True) → dict
```

Get parameters for this estimator.

This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`.

**Args:**

* `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True.

**Returns:**

* `params` (dict): Parameter names mapped to their values.

***

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

#### classmethod `load_dict`

```python
load_dict(metadata: 'Dict[str, Any]') → BaseEstimator
```

Load itself from a dict.

**Args:**

* `metadata` (Dict\[str, Any]): Dict of serialized objects.

**Returns:**

* `BaseEstimator`: The loaded object.

***

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

#### method `post_processing`

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

***

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

#### method `predict`

```python
predict(
    X: 'Data',
    fhe: 'Union[FheMode, str]' = <FheMode.DISABLE: 'disable'>
) → ndarray
```

***

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

#### method `predict_proba`

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

***

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

#### method `quantize_input`

```python
quantize_input(X: 'ndarray') → 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
