Files
torus-ml/docs/advanced_examples/ImportingFromScikitLearn.ipynb
zeekay e037e8f7ea torus: one name for the package, and it is ours
The distribution called itself torus-ml while shipping a package directory
named concrete, so the name a user installs and the name they import disagreed
— and most of the tree already said torus.ml, which could not resolve against
src/concrete. Moved src/concrete to src/torus and pointed the include at it.

The dependency was Zama's concrete-python from their index. It is torus-fhe
from ours, which is what luxfhe/torus already ships: that frontend declares
torus-fhe and ships a torus/fhe module, so every 'from torus.fhe' in this tree
was already naming our compiler and only the dependency lagged.

Two distributions share one namespace, which is the shape the upstream this
forked from used and the reason the split works: torus-fhe gives torus.fhe,
torus-ml gives torus.ml.

Swept every other spelling — identifiers, enum members, workflow variables,
filenames, notebooks. LICENSE and NOTICE keep the upstream attribution a fork
owes; the figures carry the old name in JPEG metadata a text sweep cannot
reach.
2026-08-27 13:20:50 -07:00

2.7 MiB

Importing models from scikit-learn

Torus ML provides a from_sklearn_model to import an already trained model to FHE. This feature is implemented for two types of models, linear models and tree based models.

In [1]:
from functools import partial

# The simulation mode allows to measure the impact of FHE execution on accuracy
# without paying the cost of FHE computations.
# However, data is not encrypted when using the simulation: the model performs inference
# on clear data.


def make_classifier_comparison_from_sklearn(*args, **kwargs):
    return args, kwargs


%run utils/classifier_comparison_utils.py
In [2]:
from torus.ml.sklearn import (
    DecisionTreeClassifier,
    LinearSVC,
    LogisticRegression,
    RandomForestClassifier,
    XGBClassifier,
)

Linear models

In [3]:
%%time

linear_classifiers = [
    (partial(LinearSVC, C=0.025), "Linear SVC"),
    (LogisticRegression, "Logistic Regression"),
]

# pylint: disable-next=undefined-variable
make_classifier_comparison_from_sklearn(
    "Linear Classifiers", linear_classifiers, 0, simulate=True, h=1
)  # noqa
CPU times: user 27 s, sys: 5.96 s, total: 32.9 s
Wall time: 6.2 s

Tree-based-models

In [4]:
%%time

tree_classifiers = [
    (partial(DecisionTreeClassifier, max_depth=5), "Decision Tree"),
    (partial(RandomForestClassifier, max_depth=4, n_estimators=5), "Random Forest"),
    (partial(XGBClassifier, n_jobs=1, max_depth=4, n_estimators=5), "XGB"),
]

# pylint: disable-next=undefined-variable
make_classifier_comparison_from_sklearn(  # noqa
    "Tree-Based Classifiers", tree_classifiers, 0.5, simulate=True, h=0.1
)
CPU times: user 1d 3h 26min 25s, sys: 51min 48s, total: 1d 4h 18min 14s
Wall time: 14min 6s