Linear models
This page explains Concrete ML linear models for both classification and regression. These models are based on scikit-learn linear models.
Supported models for encrypted inference
The following models are supported for training on clear data and predicting on encrypted data. Their API is similar the one of scikit-learn. These models are also compatible with some of scikit-learn's main workflows, such as Pipeline()
and GridSearch()
.
Supported models for encrypted training
In addition to predicting on encrypted data, the following models support training on encrypted data.
| SGDClassifier | SGDClassifier |
Quantization parameters
The n_bits
parameter controls the bit-width of the inputs and weights of the linear models. Linear models do not use table lookups and thus alllows weight and inputs to be high precision integers.
For models with input dimensions up to 300
, the parameter n_bits
can be set to 8
or more. When the input dimensions are larger, n_bits
must be reduced to 6-7
. In many cases, quantized models can preserve all performance metrics compared to the non-quantized float models from scikit-learn when n_bits
is down to 6
. You should validate accuracy on held-out test sets and adjust n_bits
accordingly.
For optimal results, you can use standard or min-max normalization to achieve a similar distribution of individual features. When there are many one-hot features, consider Principal Component Analysis as a pre-processing stage.
For a more detailed comparison of the impact of such pre-processing, please refer to the logistic regression notebook.
Pre-trained models
You can convert an already trained scikit-learn linear model to a Concrete ML one by using the from_sklearn_model
method. See the following example.
Example
The following example shows how to train a LogisticRegression model on a simple data-set and then use FHE to perform inference on encrypted data. You can find a more complete example in the LogisticRegression notebook.
Model accuracy
The figure below compares the decision boundary of the FHE classifier and a scikit-learn model executed in clear. You can find the complete code in the LogisticRegression notebook.
The overall accuracy scores are identical (93%) between the scikit-learn model (executed in the clear) and the Concrete ML one (executed in FHE). In fact, quantization has little impact on the decision boundaries, as linear models can use large precision numbers when quantizing inputs and weights in Concrete ML. Additionally, as the linear models do not use Programmable Boostrapping, the FHE computations are always exact, irrespective of the PBS error tolerance setting. This ensures that the FHE predictions are always identical to the quantized clear ones.
Loading a pre-trained model
An alternative to the example above is to train a scikit-learn model in a separate step and then to convert it to Concrete ML.
Zama 5-Question Developer Survey
We want to hear from you! Take 1 minute to share your thoughts and helping us enhance our documentation and libraries. 👉 Click here to participate.
Last updated