Linear Models
Last updated
Last updated
Concrete-ML provides several of the most popular linear models for regression
and classification
that can be found in Scikit-learn:
Concrete-ML | scikit-learn |
---|---|
Using these models in FHE is extremely similar to what can be done with scikit-learn's API, making it easy for data scientists who are used to this framework to get started with Concrete-ML.
Models are also compatible with some of scikit-learn's main workflows, such as Pipeline()
and GridSearch()
.
The n_bits
parameter controls the bit-width of the inputs and weights of the linear models. When non-linear mapping is applied by the model, such as exp or sigmoid, currently Concrete-ML applies it on the client-side, on clear-text values that are the decrypted output of the linear part of the model. Thus, Linear Models do not use table lookups, and can, therefore, use high precision integers for weight and inputs. The n_bits
parameter can be set to 8
or more bits for models with up to 300 input dimensions. When the input has more dimensions, n_bits
must be reduced to 6-7
. Accuracy and R2 scores are preserved down to n_bits=6
, compared to the non-quantized float models from scikit-learn.
Here is an example below of how to use a LogisticRegression model in FHE on a simple data set for classification. A more complete example can be found in the LogisticRegression notebook.
We can then plot the decision boundary of the classifier and compare those results with a scikit-learn model executed in clear. The complete code can be found 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 are able to consider large precision numbers when quantizing inputs and weights in Concrete-ML. Additionally, as the linear models do not use PBS, the FHE computations are always exact, meaning the FHE predictions are always identical to the quantized clear ones.