!pip install virtualenv
!virtualenv venv
!source venv/bin/activate
!pip install -U pip wheel setuptools
!pip install concrete-ml
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from concrete.ml.sklearn import LogisticRegression
Lets create a synthetic data-set
x, y = make_classification(n_samples=100, class_sep=2, n_features=30, random_state=42)
Split the data-set into a train and test set
X_train, X_test, y_train, y_test = train_test_split(
x, y, test_size=0.2, random_state=42
)
Now we train in the clear and quantize the weights
model = LogisticRegression(n_bits=8)
model.fit(X_train, y_train)
We can simulate the predictions in the clear
y_pred_clear = model.predict(X_test)
We then compile on a representative set
model.compile(X_train)
Finally we run the inference on encrypted inputs !
y_pred_fhe = model.predict(X_test, fhe=“execute”)
print(“In clear :”, y_pred_clear)
print(“In FHE :”, y_pred_fhe)
print(f"Similarity: {int((y_pred_fhe == y_pred_clear).mean()*100)}%")
Output:
# In clear : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0]
# In FHE : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0]
# Similarity: 100%
RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
ImportError Traceback (most recent call last)
in <cell line: 1>()
----> 1 from sklearn.datasets import make_classification
2 from sklearn.model_selection import train_test_split
3 from concrete.ml.sklearn import LogisticRegression
4
5 # Lets create a synthetic data-set
7 frames
/usr/local/lib/python3.10/dist-packages/numpy/testing/_private/utils.py in
23 intp, float32, empty, arange, array_repr, ndarray, isnat, array)
24 from numpy import isfinite, isnan, isinf
—> 25 import numpy.linalg.lapack_lite
26
27 from io import StringIO
ImportError: numpy.core.multiarray failed to import