concrete.ml.sklearn.neighbors.md

module concrete.ml.sklearn.neighbors

Implement sklearn linear model.


class KNeighborsClassifier

A k-nearest neighbors classifier model with FHE.

Parameters:

  • n_bits (int): Number of bits to quantize the model. The value will be used for quantizing inputs and X_fit. Default to 3.

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

method __init__

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

property fhe_circuit

Get the FHE circuit.

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

Returns:

  • Circuit: The FHE circuit.


property is_compiled

Indicate if the model is compiled.

Returns:

  • bool: If the model is compiled.


property is_fitted

Indicate if the model is fitted.

Returns:

  • bool: If the model is fitted.


property onnx_model

Get the ONNX model.

Is None if the model is not fitted.

Returns:

  • onnx.ModelProto: The ONNX model.


method dump_dict

dump_dict() → Dict[str, Any]

classmethod load_dict

load_dict(metadata: Dict)

method predict_proba

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

Predict class probabilities.

Args:

  • X (Data): The input values to predict, as a Numpy array, Torch tensor, Pandas DataFrame or List.

  • fhe (Union[FheMode, str]): The mode to use for prediction. Can be FheMode.DISABLE for Concrete ML Python inference, FheMode.SIMULATE for FHE simulation and FheMode.EXECUTE for actual FHE execution. Can also be the string representation of any of these values. Default to FheMode.DISABLE.

Raises:

  • NotImplementedError: The method is not implemented for now.

Last updated