TreeEnsembleRegressor and parallelisation#

The operator TreeEnsembleClassifier describe any tree model (decision tree, random forest, gradient boosting). The runtime is usually implements in C/C++ and uses parallelisation. The notebook studies the impact of the parallelisation.

Graph#

The following dummy graph shows the time ratio between two runtimes depending on the number of observations in a batch (N) and the number of trees in the forest.

from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from mlprodict.onnxrt import OnnxInference
from onnxruntime import InferenceSession
from skl2onnx import to_onnx
from mlprodict.onnxrt.validate.validate_benchmark import benchmark_fct
import sklearn
import numpy
from tqdm import tqdm
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.datasets import make_classification
import matplotlib.pyplot as plt
from mlprodict.plotting.plotting import plot_benchmark_metrics


def plot_metric(metric, ax=None, xlabel="N", ylabel="trees", middle=1.,
                transpose=False, shrink=1.0, title=None, figsize=None):
    if figsize is not None and ax is None:
        _, ax = plt.subplots(1, 1, figsize=figsize)

    ax, cbar = plot_benchmark_metrics(
        metric, ax=ax, xlabel=xlabel, ylabel=ylabel, middle=middle,
        transpose=transpose, cbar_kw={'shrink': shrink})
    if title is not None:
        ax.set_title(title)
    return ax


data = {(1, 1): 0.1, (10, 1): 1, (1, 10): 2,
        (10, 10): 100, (100, 1): 100, (100, 10): 1000}

fig, ax = plt.subplots(1, 2, figsize=(10, 4))
plot_metric(data, ax[0], shrink=0.6)
plot onnx tree ensemble parallel

Out:

<AxesSubplot:xlabel='N', ylabel='trees'>
plot_metric(data, ax[1], transpose=True)

Out:

<AxesSubplot:xlabel='trees', ylabel='N'>

scikit-learn: T trees vs 1 tree#

Let’s do first compare a GradientBoostingClassifier from scikit-learn with 1 tree against multiple trees.

# In[4]:


ntest = 10000
X, y = make_classification(
    n_samples=10000 + ntest, n_features=10, n_informative=5,
    n_classes=2, random_state=11)
X_train, X_test, y_train, y_test = X[:-
                                     ntest], X[-ntest:], y[:-ntest], y[-ntest:]
ModelToTest = GradientBoostingClassifier

N = [1, 10, 100, 1000, 10000]
T = [1, 2, 10, 20, 50]

models = {}
for nt in tqdm(T):
    rf = ModelToTest(n_estimators=nt, max_depth=7).fit(X_train, y_train)
    models[nt] = rf

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:00<00:00,  6.31it/s]
 40%|####      | 2/5 [00:00<00:00,  4.01it/s]
 60%|######    | 3/5 [00:02<00:01,  1.18it/s]
 80%|########  | 4/5 [00:05<00:01,  1.74s/it]
100%|##########| 5/5 [00:12<00:00,  3.91s/it]
100%|##########| 5/5 [00:12<00:00,  2.58s/it]

Benchmark.

def benchmark(X, fct1, fct2, N, repeat=10, number=20):

    def ti(r, n):
        if n <= 1:
            return 40 * r
        if n <= 10:
            return 10 * r
        if n <= 100:
            return 4 * r
        if n <= 1000:
            return r
        return r // 2

    with sklearn.config_context(assume_finite=True):
        # to warm up the engine
        time_kwargs = {n: dict(repeat=10, number=10) for n in N}
        benchmark_fct(fct1, X, time_kwargs=time_kwargs, skip_long_test=False)
        benchmark_fct(fct2, X, time_kwargs=time_kwargs, skip_long_test=False)
        # real measure
        time_kwargs = {n: dict(repeat=ti(repeat, n), number=number) for n in N}
        res1 = benchmark_fct(
            fct1, X, time_kwargs=time_kwargs, skip_long_test=False)
        res2 = benchmark_fct(
            fct2, X, time_kwargs=time_kwargs, skip_long_test=False)
    res = {}
    for r in sorted(res1):
        r1 = res1[r]
        r2 = res2[r]
        ratio = r2['ttime'] / r1['ttime']
        res[r] = ratio
    return res


def tree_benchmark(X, fct1, fct2, T, N, repeat=20, number=10):
    bench = {}
    for t in tqdm(T):
        if callable(X):
            x = X(t)
        else:
            x = X
        r = benchmark(x, fct1(t), fct2(t), N, repeat=repeat, number=number)
        for n, v in r.items():
            bench[n, t] = v
    return bench


bench = tree_benchmark(X_test.astype(numpy.float32),
                       lambda t: models[1].predict,
                       lambda t: models[t].predict, T, N)

list(bench.items())[:3]

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:16<01:05, 16.38s/it]
 40%|####      | 2/5 [00:32<00:49, 16.44s/it]
 60%|######    | 3/5 [00:50<00:34, 17.12s/it]
 80%|########  | 4/5 [01:10<00:18, 18.14s/it]
100%|##########| 5/5 [01:35<00:00, 20.48s/it]
100%|##########| 5/5 [01:35<00:00, 19.03s/it]

[((1, 1), 1.0009461643436859), ((10, 1), 0.9873291269542542), ((100, 1), 0.9901748081445227)]

Graph.

plot_metric(bench, title="scikit-learn 1 tree vs scikit-learn T trees\n"
            "< 1 means onnxruntime is faster")
scikit-learn 1 tree vs scikit-learn T trees < 1 means onnxruntime is faster

Out:

<AxesSubplot:title={'center':'scikit-learn 1 tree vs scikit-learn T trees\n< 1 means onnxruntime is faster'}, xlabel='N', ylabel='trees'>

As expected, all ratio on first line are close to 1 since both models are the same. fourth line, second column (T=20, N=10) means an ensemble with 20 trees is slower to compute the predictions of 10 observations in a batch compare to an ensemble with 1 tree.

scikit-learn against onnxuntime#

X32 = X_test.astype(numpy.float32)
models_onnx = {t: to_onnx(m, X32[:1]) for t, m in models.items()}


sess_models = {t: InferenceSession(mo.SerializeToString())
               for t, mo in models_onnx.items()}

Out:

/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)

Benchmark.

bench_ort = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: models[t].predict_proba,
    lambda t: (lambda x, t_=t, se=sess_models: se[t_].run(None, {'X': x})),
    T, N)
bench_ort

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:11<00:47, 11.96s/it]
 40%|####      | 2/5 [00:24<00:36, 12.10s/it]
 60%|######    | 3/5 [00:39<00:27, 13.58s/it]
 80%|########  | 4/5 [00:56<00:15, 15.08s/it]
100%|##########| 5/5 [01:20<00:00, 18.25s/it]
100%|##########| 5/5 [01:20<00:00, 16.15s/it]

{(1, 1): 0.10319046266728345, (10, 1): 0.11911137704125449, (100, 1): 0.27870334257428786, (1000, 1): 1.4690351069118248, (10000, 1): 4.081341443666262, (1, 2): 0.1029979205423275, (10, 2): 0.11906848563630591, (100, 2): 0.27905736381397994, (1000, 2): 1.4310597171150565, (10000, 2): 3.564591631885778, (1, 10): 0.10387373481026677, (10, 10): 0.12896240411807605, (100, 10): 0.3646358223472523, (1000, 10): 1.4449965362811141, (10000, 10): 2.4526305468073892, (1, 20): 0.10437382475817494, (10, 20): 0.1350098223658613, (100, 20): 0.31937126431548646, (1000, 20): 1.064301130325886, (10000, 20): 1.5666669202885322, (1, 50): 0.10114284214223039, (10, 50): 0.16342439763868535, (100, 50): 0.26714565246464994, (1000, 50): 0.7077595139278611, (10000, 50): 0.9114166833164714}

Graphs

plot_metric(bench_ort, title="scikit-learn vs onnxruntime\n < 1 "
            "means onnxruntime is faster")
scikit-learn vs onnxruntime  < 1 means onnxruntime is faster

Out:

<AxesSubplot:title={'center':'scikit-learn vs onnxruntime\n < 1 means onnxruntime is faster'}, xlabel='N', ylabel='trees'>

We see onnxruntime is fast for small batches, still faster but not that much for big batches.

ZipMap operator#

ZipMap just creates a new container for the same results. The copy may impact the ratio. Let’s remove it from the equation.

X32 = X_test.astype(numpy.float32)
models_onnx = {t: to_onnx(m, X32[:1],
                          options={ModelToTest: {'zipmap': False}})
               for t, m in models.items()}

sess_models = {t: InferenceSession(mo.SerializeToString())
               for t, mo in models_onnx.items()}

Out:

/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)

Benchmarks.

bench_ort = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: models[t].predict_proba,
    lambda t: (lambda x, t_=t, se=sess_models: se[t_].run(None, {'X': x})),
    T, N)

bench_ort

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:08<00:34,  8.67s/it]
 40%|####      | 2/5 [00:17<00:26,  8.77s/it]
 60%|######    | 3/5 [00:30<00:21, 10.65s/it]
 80%|########  | 4/5 [00:45<00:12, 12.51s/it]
100%|##########| 5/5 [01:08<00:00, 16.25s/it]
100%|##########| 5/5 [01:08<00:00, 13.73s/it]

{(1, 1): 0.09284735771597498, (10, 1): 0.09518147665603957, (100, 1): 0.10450097671403283, (1000, 1): 0.13053350586926463, (10000, 1): 0.18189063909253667, (1, 2): 0.09325083410585396, (10, 2): 0.09740867780697102, (100, 2): 0.10796227113854902, (1000, 2): 0.137886624104243, (10000, 2): 0.20022872277819245, (1, 10): 0.09384815683995154, (10, 10): 0.10393128770374264, (100, 10): 0.2256849570717144, (1000, 10): 0.7215159529567793, (10000, 10): 1.4041556965470219, (1, 20): 0.09330447498580412, (10, 20): 0.11483563310127191, (100, 20): 0.20601222061612107, (1000, 20): 0.5909812348929128, (10000, 20): 1.0323049797461297, (1, 50): 0.09402424754716088, (10, 50): 0.1472050206634615, (100, 50): 0.20000220036545327, (1000, 50): 0.48057265247733577, (10000, 50): 0.8163295747403458}

Graphs.

plot_metric(bench_ort, title="scikit-learn vs onnxruntime (no zipmap)\n < 1 "
            "means onnxruntime is faster")


# ZipMap removal significantly improves.
#
# Implementation details for mlprodict runtime
# ++++++++++++++++++++++++++++++++++++++++++++
#
# The runtime implemented in :epkg:`mlprodict` mostly relies on
# two files:
# * `op_tree_ensemble_common_p_agg_.hpp <https://github.com/sdpython/
#   mlprodict/blob/master/mlprodict/onnxrt/ops_cpu/
#   op_tree_ensemble_common_p_agg_.hpp>`_
# * `op_tree_ensemble_common_p_.hpp <https://github.com/sdpython/
#   mlprodict/blob/master/mlprodict/onnxrt/ops_cpu/
#   op_tree_ensemble_common_p_.hpp>`_
#
# The runtime builds a tree structure, computes the output of every
# tree and then agregates them. The implementation distringuishes
# when the batch size contains only 1 observations or many.
# It parallelizes on the following conditions:
# * if the batch size $N \geqslant N_0$, it then parallelizes per
#   observation, asuming every one is independant,
# * if the batch size $N = 1$ and the number of trees
#   $T \geqslant T_0$, it then parallelizes per tree.
#
# scikit-learn against mlprodict, no parallelisation
# ++++++++++++++++++++++++++++++++++++++++++++++++++


oinf_models = {t: OnnxInference(mo, runtime="python_compiled")
               for t, mo in models_onnx.items()}
scikit-learn vs onnxruntime (no zipmap)  < 1 means onnxruntime is faster

Let’s modify the thresholds which trigger the parallelization.

for _, oinf in oinf_models.items():
    oinf.sequence_[0].ops_.rt_.omp_tree_ = 10000000
    oinf.sequence_[0].ops_.rt_.omp_N_ = 10000000

Benchmarks.

bench_mlp = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: models[t].predict,
    lambda t: (lambda x, t_=t, oi=oinf_models: oi[t_].run({'X': x})),
    T, N)
bench_mlp

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:09<00:37,  9.29s/it]
 40%|####      | 2/5 [00:19<00:28,  9.55s/it]
 60%|######    | 3/5 [00:32<00:22, 11.45s/it]
 80%|########  | 4/5 [00:52<00:14, 14.77s/it]
100%|##########| 5/5 [01:30<00:00, 23.12s/it]
100%|##########| 5/5 [01:30<00:00, 18.10s/it]

{(1, 1): 0.05435222921975988, (10, 1): 0.05785355201946071, (100, 1): 0.08891498263594814, (1000, 1): 0.29658686844977755, (10000, 1): 0.7123192577762656, (1, 2): 0.05494814512291604, (10, 2): 0.06006245523370635, (100, 2): 0.10229975762027066, (1000, 2): 0.3747620756153539, (10000, 2): 0.8537179643148471, (1, 10): 0.05633205614819773, (10, 10): 0.07321590178028028, (100, 10): 0.21911267847755833, (1000, 10): 0.8893395269312945, (10000, 10): 1.5717209421523197, (1, 20): 0.057943899977201, (10, 20): 0.0935092654106385, (100, 20): 0.38108940244503137, (1000, 20): 1.414231195706973, (10000, 20): 2.171487823258139, (1, 50): 0.06157965465288015, (10, 50): 0.1388967812960219, (100, 50): 0.6930885542986098, (1000, 50): 2.0818161561584065, (10000, 50): 2.7070492067386804}

Graphs.

plot_metric(bench_mlp, title="scikit-learn vs mlprodict\n < 1 "
            "means mlprodict is faster")
scikit-learn vs mlprodict  < 1 means mlprodict is faster

Out:

<AxesSubplot:title={'center':'scikit-learn vs mlprodict\n < 1 means mlprodict is faster'}, xlabel='N', ylabel='trees'>

Let’s compare onnxruntime against mlprodict.

bench_mlp_ort = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: (lambda x, t_=t, se=sess_models: se[t_].run(None, {'X': x})),
    lambda t: (lambda x, t_=t, oi=oinf_models: oi[t_].run({'X': x})),
    T, N)
bench_mlp_ort

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:01<00:07,  1.89s/it]
 40%|####      | 2/5 [00:04<00:06,  2.06s/it]
 60%|######    | 3/5 [00:10<00:08,  4.25s/it]
 80%|########  | 4/5 [00:22<00:07,  7.22s/it]
100%|##########| 5/5 [00:49<00:00, 14.29s/it]
100%|##########| 5/5 [00:49<00:00,  9.91s/it]

{(1, 1): 0.6269171342538937, (10, 1): 0.6445623629134744, (100, 1): 0.893998104656049, (1000, 1): 2.400787342444085, (10000, 1): 4.293639602640847, (1, 2): 0.6224635788330347, (10, 2): 0.6576975332447942, (100, 2): 1.021557344596475, (1000, 2): 2.833212025338736, (10000, 2): 4.580094978673054, (1, 10): 0.6384829041544642, (10, 10): 0.7488561082833768, (100, 10): 0.9875806358372191, (1000, 10): 1.2308696710965485, (10000, 10): 1.4817305629112225, (1, 20): 0.6531918395840522, (10, 20): 0.862259506761615, (100, 20): 1.8507643186961633, (1000, 20): 2.4621116606670026, (10000, 20): 2.83196615060277, (1, 50): 0.6930712796852624, (10, 50): 0.992167978322196, (100, 50): 3.5781380431314673, (1000, 50): 4.456485774157192, (10000, 50): 4.601123425402485}

Graphs.

plot_metric(bench_mlp_ort, title="onnxruntime vs mlprodict\n < 1 means "
            "mlprodict is faster\nno parallelisation")
onnxruntime vs mlprodict  < 1 means mlprodict is faster no parallelisation

Out:

<AxesSubplot:title={'center':'onnxruntime vs mlprodict\n < 1 means mlprodict is faster\nno parallelisation'}, xlabel='N', ylabel='trees'>

This implementation is faster except for high number of trees or high number of observations. Let’s add parallelisation for trees and observations.

for _, oinf in oinf_models.items():
    oinf.sequence_[0].ops_.rt_.omp_tree_ = 2
    oinf.sequence_[0].ops_.rt_.omp_N_ = 2


bench_mlp_para = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: models[t].predict,
    lambda t: (lambda x, t_=t, oi=oinf_models: oi[t_].run({'X': x})),
    T, N)

bench_mlp_para

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:09<00:37,  9.39s/it]
 40%|####      | 2/5 [00:19<00:28,  9.59s/it]
 60%|######    | 3/5 [00:30<00:20, 10.21s/it]
 80%|########  | 4/5 [00:42<00:11, 11.25s/it]
100%|##########| 5/5 [01:01<00:00, 13.94s/it]
100%|##########| 5/5 [01:01<00:00, 12.33s/it]

{(1, 1): 0.054116739055139904, (10, 1): 0.06487917457400931, (100, 1): 0.09620220516305011, (1000, 1): 0.31403696210628745, (10000, 1): 0.7333490308999471, (1, 2): 0.05432784741707317, (10, 2): 0.06635664112559152, (100, 2): 0.10706983308634843, (1000, 2): 0.43248189436222495, (10000, 2): 0.8406107402666548, (1, 10): 0.06949281214237439, (10, 10): 0.074037351167408, (100, 10): 0.08795782354153403, (1000, 10): 0.164817673042389, (10000, 10): 0.2579107811541199, (1, 20): 0.06554114885351112, (10, 20): 0.06991476768792772, (100, 20): 0.0866334454952105, (1000, 20): 0.1590080350004976, (10000, 20): 0.22170278941457888, (1, 50): 0.06392921123294237, (10, 50): 0.0660868188988398, (100, 50): 0.0917717371931999, (1000, 50): 0.19446526232312464, (10000, 50): 0.2098067738912861}

Graphs.

plot_metric(bench_mlp_para, title="scikit-learn vs mlprodict\n < 1 means "
            "mlprodict is faster\nparallelisation")
scikit-learn vs mlprodict  < 1 means mlprodict is faster parallelisation

Out:

<AxesSubplot:title={'center':'scikit-learn vs mlprodict\n < 1 means mlprodict is faster\nparallelisation'}, xlabel='N', ylabel='trees'>

Parallelisation does improve the computation time when N is big. Let’s compare with and without parallelisation.

bench_para = {}
for k, v in bench_mlp.items():
    bench_para[k] = bench_mlp_para[k] / v


plot_metric(bench_para, title="mlprodict vs mlprodict parallelized\n < 1 "
            "means parallelisation is faster")
mlprodict vs mlprodict parallelized  < 1 means parallelisation is faster

Out:

<AxesSubplot:title={'center':'mlprodict vs mlprodict parallelized\n < 1 means parallelisation is faster'}, xlabel='N', ylabel='trees'>

Parallelisation per trees does not seem to be efficient. Let’s confirm with a proper benchmark as the previous merges results from two benchmarks.

for _, oinf in oinf_models.items():
    oinf.sequence_[0].ops_.rt_.omp_tree_ = 1000000
    oinf.sequence_[0].ops_.rt_.omp_N_ = 1000000

oinf_models_para = {t: OnnxInference(mo, runtime="python_compiled")
                    for t, mo in models_onnx.items()}

for _, oinf in oinf_models_para.items():
    oinf.sequence_[0].ops_.rt_.omp_tree_ = 2
    oinf.sequence_[0].ops_.rt_.omp_N_ = 2

bench_mlp_para = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: (lambda x, t_=t, oi=oinf_models: oi[t_].run({'X': x})),
    lambda t: (lambda x, t_=t, oi=oinf_models_para: oi[t_].run({'X': x})),
    T, N, repeat=20, number=20)

bench_mlp_para

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:03<00:13,  3.41s/it]
 40%|####      | 2/5 [00:07<00:11,  3.78s/it]
 60%|######    | 3/5 [00:15<00:11,  5.66s/it]
 80%|########  | 4/5 [00:30<00:09,  9.36s/it]
100%|##########| 5/5 [01:06<00:00, 19.00s/it]
100%|##########| 5/5 [01:06<00:00, 13.30s/it]

{(1, 1): 0.9980417860619196, (10, 1): 1.1061699983158721, (100, 1): 0.9822389039623132, (1000, 1): 0.8685569907707635, (10000, 1): 0.8250392387549733, (1, 2): 0.9891746411341485, (10, 2): 1.079904168531088, (100, 2): 0.9268231401844608, (1000, 2): 0.8125708729382162, (10000, 2): 0.7750487348059522, (1, 10): 1.2144995794031594, (10, 10): 0.974963073198892, (100, 10): 0.39582623575109604, (1000, 10): 0.18238333768017073, (10000, 10): 0.16262383961521915, (1, 20): 1.1783890720672612, (10, 20): 0.7582400225573755, (100, 20): 0.23358076057951932, (1000, 20): 0.11564611553441313, (10000, 20): 0.10531718010788763, (1, 50): 1.0366136303697782, (10, 50): 0.47214795252290803, (100, 50): 0.12863364051883722, (1000, 50): 0.08144845175327128, (10000, 50): 0.07857700488708953}

Graph.

plot_metric(bench_mlp_para, title="mlprodict vs mlprodict parallelized\n < 1 "
            "means parallelisation is faster\nsame baseline")
mlprodict vs mlprodict parallelized  < 1 means parallelisation is faster same baseline

Out:

<AxesSubplot:title={'center':'mlprodict vs mlprodict parallelized\n < 1 means parallelisation is faster\nsame baseline'}, xlabel='N', ylabel='trees'>

It should be run on different machines. On the current one, parallelisation per trees (when N=1) does not seem to help. Parallelisation for a small number of observations does not seem to help either. So we need to find some threshold.

Parallelisation per trees#

Let’s study the parallelisation per tree. We need to train new models.

# In[33]:


N2 = [1, 10]
T2 = [1, 2, 10, 50, 100, 150, 200, 300, 400, 500]

models2 = {}
for nt in tqdm(T2):
    rf = ModelToTest(n_estimators=nt, max_depth=7).fit(X_train, y_train)
    models2[nt] = rf

Out:

  0%|          | 0/10 [00:00<?, ?it/s]
 10%|#         | 1/10 [00:00<00:01,  6.39it/s]
 20%|##        | 2/10 [00:00<00:01,  4.04it/s]
 30%|###       | 3/10 [00:02<00:05,  1.18it/s]
 40%|####      | 4/10 [00:09<00:21,  3.56s/it]
 50%|#####     | 5/10 [00:25<00:39,  7.83s/it]
 60%|######    | 6/10 [00:48<00:51, 12.99s/it]
 70%|#######   | 7/10 [01:18<00:56, 18.76s/it]
 80%|########  | 8/10 [02:04<00:54, 27.40s/it]
 90%|######### | 9/10 [03:05<00:37, 37.97s/it]
100%|##########| 10/10 [04:22<00:00, 49.87s/it]
100%|##########| 10/10 [04:22<00:00, 26.24s/it]

Conversion to ONNX.

X32 = X_test.astype(numpy.float32)
models2_onnx = {t: to_onnx(m, X32[:1]) for t, m in models2.items()}

oinf_models2 = {t: OnnxInference(mo, runtime="python_compiled")
                for t, mo in models2_onnx.items()}
for _, oinf in oinf_models2.items():
    oinf.sequence_[0].ops_.rt_.omp_tree_ = 1000000
    oinf.sequence_[0].ops_.rt_.omp_N_ = 1000000

oinf_models2_para = {t: OnnxInference(
    mo, runtime="python_compiled") for t, mo in models2_onnx.items()}
for _, oinf in oinf_models2_para.items():
    oinf.sequence_[0].ops_.rt_.omp_tree_ = 2
    oinf.sequence_[0].ops_.rt_.omp_N_ = 100

Out:

/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)
/usr/local/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
  warnings.warn(msg, category=FutureWarning)

And benchmark.

# In[36]:


bench_mlp_tree = tree_benchmark(
    X_test.astype(numpy.float32),
    lambda t: (lambda x, t_=t, oi=oinf_models2: oi[t_].run({'X': x})),
    lambda t: (lambda x, t_=t, oi=oinf_models2_para: oi[t_].run({'X': x})),
    T2, N2, repeat=20, number=20)
bench_mlp_tree

Out:

  0%|          | 0/10 [00:00<?, ?it/s]
 10%|#         | 1/10 [00:02<00:19,  2.12s/it]
 20%|##        | 2/10 [00:04<00:16,  2.12s/it]
 30%|###       | 3/10 [00:06<00:15,  2.25s/it]
 40%|####      | 4/10 [00:09<00:14,  2.48s/it]
 50%|#####     | 5/10 [00:12<00:14,  2.81s/it]
 60%|######    | 6/10 [00:17<00:13,  3.28s/it]
 70%|#######   | 7/10 [00:22<00:11,  3.97s/it]
 80%|########  | 8/10 [00:31<00:11,  5.57s/it]
 90%|######### | 9/10 [00:49<00:09,  9.36s/it]
100%|##########| 10/10 [01:13<00:00, 13.95s/it]
100%|##########| 10/10 [01:13<00:00,  7.34s/it]

{(1, 1): 1.0007585615778265, (10, 1): 1.0020352670108665, (1, 2): 0.9988253333907794, (10, 2): 0.9982423376550369, (1, 10): 1.1689396049985559, (10, 10): 1.0079898317697795, (1, 50): 1.0503675042933103, (10, 50): 0.5766214966920897, (1, 100): 0.9899200274581791, (10, 100): 0.3861318540698036, (1, 150): 0.9348481181544857, (10, 150): 0.257640410519183, (1, 200): 0.8933002350591688, (10, 200): 0.1813674144954662, (1, 300): 0.5761048121873134, (10, 300): 0.10402197565871181, (1, 400): 0.24662351177193312, (10, 400): 0.061589202367450656, (1, 500): 0.19151259334022402, (10, 500): 0.055095425977330595}

Graph.

plot_metric(
    bench_mlp_tree, transpose=True, figsize=(10, 3), shrink=0.5,
    title="mlprodict vs mlprodict parallelized\n < 1 means parallelisation "
    "is faster")
mlprodict vs mlprodict parallelized  < 1 means parallelisation is faster

Out:

<AxesSubplot:title={'center':'mlprodict vs mlprodict parallelized\n < 1 means parallelisation is faster'}, xlabel='trees', ylabel='N'>

The parallelisation starts to be below 1 after 400 trees. For 10 observations, there is no parallelisation neither by trees nor by observations. Ratios are close to 1. The gain obviously depends on the tree depth. You can try with a different max depth and the number of trees parallelisation becomes interesting depending on the tree depth.

Multi-Class DecisionTreeClassifier#

Same experiment when the number of tree is 1 but then we change the number of classes.

ModelToTest = DecisionTreeClassifier

C = [2, 5, 10, 15, 20, 30, 40, 50]
N = [1, 10, 100, 1000, 10000]
trees = {}
for cl in tqdm(C):

    ntest = 10000
    X, y = make_classification(
        n_samples=10000 + ntest, n_features=12, n_informative=8,
        n_classes=cl, random_state=11)
    X_train, X_test, y_train, y_test = (
        X[:-ntest], X[-ntest:], y[:-ntest], y[-ntest:])

    dt = ModelToTest(max_depth=7).fit(X_train, y_train)

    X32 = X_test.astype(numpy.float32)
    monnx = to_onnx(dt, X32[:1])
    oinf = OnnxInference(monnx)
    oinf.sequence_[0].ops_.rt_.omp_N_ = 1000000
    trees[cl] = dict(model=dt, X_test=X_test, X32=X32, monnx=monnx, oinf=oinf)


bench_dt = tree_benchmark(lambda cl: trees[cl]['X32'],
                          lambda cl: trees[cl]['model'].predict_proba,
                          lambda cl: (
                              lambda x, c=cl: trees[c]['oinf'].run({'X': x})),
                          C, N)

bench_dt

Out:

  0%|          | 0/8 [00:00<?, ?it/s]
 12%|#2        | 1/8 [00:00<00:02,  3.31it/s]
 25%|##5       | 2/8 [00:00<00:01,  3.14it/s]
 38%|###7      | 3/8 [00:00<00:01,  2.93it/s]
 50%|#####     | 4/8 [00:01<00:01,  2.74it/s]
 62%|######2   | 5/8 [00:01<00:01,  2.56it/s]
 75%|#######5  | 6/8 [00:02<00:00,  2.30it/s]
 88%|########7 | 7/8 [00:02<00:00,  2.06it/s]
100%|##########| 8/8 [00:03<00:00,  1.85it/s]
100%|##########| 8/8 [00:03<00:00,  2.22it/s]

  0%|          | 0/8 [00:00<?, ?it/s]
 12%|#2        | 1/8 [00:04<00:33,  4.76s/it]
 25%|##5       | 2/8 [00:09<00:29,  4.95s/it]
 38%|###7      | 3/8 [00:15<00:25,  5.17s/it]
 50%|#####     | 4/8 [00:21<00:21,  5.43s/it]
 62%|######2   | 5/8 [00:27<00:17,  5.68s/it]
 75%|#######5  | 6/8 [00:33<00:12,  6.05s/it]
 88%|########7 | 7/8 [00:41<00:06,  6.48s/it]
100%|##########| 8/8 [00:49<00:00,  6.94s/it]
100%|##########| 8/8 [00:49<00:00,  6.16s/it]

{(1, 2): 0.5206537507877722, (10, 2): 0.5211111443391622, (100, 2): 0.5350203831241831, (1000, 2): 0.7514205030042139, (10000, 2): 0.9956542869350409, (1, 5): 0.5298673238792098, (10, 5): 0.5263722713456684, (100, 5): 0.5721261862123131, (1000, 5): 0.7849592449821156, (10000, 5): 1.0159643703907613, (1, 10): 0.5206775146680526, (10, 10): 0.5232810182663737, (100, 10): 0.561835798881574, (1000, 10): 0.7465080057067311, (10000, 10): 0.9218967137094728, (1, 15): 0.521528417661577, (10, 15): 0.5200815719858182, (100, 15): 0.5693457814712225, (1000, 15): 0.7325951586728551, (10000, 15): 0.8870443602063696, (1, 20): 0.524139914496761, (10, 20): 0.5231385067000542, (100, 20): 0.5630321565815967, (1000, 20): 0.7056875209258635, (10000, 20): 0.8401050934322034, (1, 30): 0.5241065317658261, (10, 30): 0.5287260145475366, (100, 30): 0.5667601569079135, (1000, 30): 0.6676141825701171, (10000, 30): 0.792867018751725, (1, 40): 0.5450905371992687, (10, 40): 0.5266099724100872, (100, 40): 0.570002812607713, (1000, 40): 0.6523062703279384, (10000, 40): 0.7801910900094315, (1, 50): 0.5211576293177239, (10, 50): 0.5297765501070187, (100, 50): 0.5711369771490267, (1000, 50): 0.6384474203714021, (10000, 50): 0.7763861533295489}

Graph.

plot_metric(bench_dt, ylabel="classes", transpose=True, shrink=0.75,
            title="scikit-learn vs mlprodict (DecisionTreeClassifier) \n"
            "< 1 means mlprodict is faster\n no parallelisation")
scikit-learn vs mlprodict (DecisionTreeClassifier)  < 1 means mlprodict is faster  no parallelisation

Out:

<AxesSubplot:title={'center':'scikit-learn vs mlprodict (DecisionTreeClassifier) \n< 1 means mlprodict is faster\n no parallelisation'}, xlabel='classes', ylabel='N'>

Multi-class LogisticRegression#

ModelToTest = LogisticRegression

C = [2, 5, 10, 15, 20]
N = [1, 10, 100, 1000, 10000]

models = {}
for cl in tqdm(C):

    ntest = 10000
    X, y = make_classification(
        n_samples=10000 + ntest, n_features=10, n_informative=6,
        n_classes=cl, random_state=11)
    X_train, X_test, y_train, y_test = (
        X[:-ntest], X[-ntest:], y[:-ntest], y[-ntest:])

    model = ModelToTest().fit(X_train, y_train)

    X32 = X_test.astype(numpy.float32)
    monnx = to_onnx(model, X32[:1])
    oinf = OnnxInference(monnx)
    models[cl] = dict(model=model, X_test=X_test,
                      X32=X32, monnx=monnx, oinf=oinf)


bench_lr = tree_benchmark(lambda cl: models[cl]['X32'],
                          lambda cl: models[cl]['model'].predict_proba,
                          lambda cl: (
                              lambda x, c=cl: trees[c]['oinf'].run({'X': x})),
                          C, N)
bench_lr

Out:

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:00<00:00,  9.62it/s]
 40%|####      | 2/5 [00:00<00:00,  3.57it/s]
 60%|######    | 3/5 [00:00<00:00,  2.82it/s]
 80%|########  | 4/5 [00:01<00:00,  1.95it/s]
100%|##########| 5/5 [00:02<00:00,  1.53it/s]
100%|##########| 5/5 [00:02<00:00,  1.92it/s]

  0%|          | 0/5 [00:00<?, ?it/s]
 20%|##        | 1/5 [00:05<00:20,  5.13s/it]
 40%|####      | 2/5 [00:12<00:18,  6.30s/it]
 60%|######    | 3/5 [00:20<00:14,  7.29s/it]
 80%|########  | 4/5 [00:30<00:08,  8.20s/it]
100%|##########| 5/5 [00:41<00:00,  9.16s/it]
100%|##########| 5/5 [00:41<00:00,  8.23s/it]

{(1, 2): 0.4359968201634946, (10, 2): 0.44791046674760315, (100, 2): 0.4866988699865503, (1000, 2): 0.7352842797067238, (10000, 2): 1.159552118420509, (1, 5): 0.37169330685953655, (10, 5): 0.3644311428989389, (100, 5): 0.363836680990028, (1000, 5): 0.35311969526424164, (10000, 5): 0.374232458339097, (1, 10): 0.3768812726778356, (10, 10): 0.3629562287187491, (100, 10): 0.3383087338349239, (1000, 10): 0.28302952829226147, (10000, 10): 0.2738719903625186, (1, 15): 0.3769604685854461, (10, 15): 0.3563357519503201, (100, 15): 0.31667201873502315, (1000, 15): 0.24772068680757187, (10000, 15): 0.24408288713727996, (1, 20): 0.3766504363794785, (10, 20): 0.35011475995801833, (100, 20): 0.30203662986665686, (1000, 20): 0.21513978604352335, (10000, 20): 0.2100837731539065}

Graph.

plot_metric(bench_lr, ylabel="classes",
            title="scikit-learn vs mlprodict (LogisticRegression) \n"
            "< 1 means mlprodict is faster\n no parallelisation")
scikit-learn vs mlprodict (LogisticRegression)  < 1 means mlprodict is faster  no parallelisation

Out:

<AxesSubplot:title={'center':'scikit-learn vs mlprodict (LogisticRegression) \n< 1 means mlprodict is faster\n no parallelisation'}, xlabel='N', ylabel='classes'>

Decision Tree and number of features#

ModelToTest = DecisionTreeClassifier

NF = [2, 10, 20, 40, 50, 70, 100, 200, 500, 1000]
N = [1, 10, 100, 1000, 10000, 50000]
trees_nf = {}

for nf in tqdm(NF):
    ntest = 10000
    X, y = make_classification(
        n_samples=10000 + ntest, n_features=nf, n_informative=nf // 2 + 1,
        n_redundant=0, n_repeated=0,
        n_classes=2, random_state=11)
    X_train, X_test, y_train, y_test = (
        X[:-ntest], X[-ntest:], y[:-ntest], y[-ntest:])

    dt = ModelToTest(max_depth=7).fit(X_train, y_train)

    X32 = X_test.astype(numpy.float32)
    monnx = to_onnx(dt, X32[:1])
    oinf = OnnxInference(monnx)
    oinf.sequence_[0].ops_.rt_.omp_N_ = 1000000
    trees_nf[nf] = dict(model=dt, X_test=X_test,
                        X32=X32, monnx=monnx, oinf=oinf)


bench_dt_nf = tree_benchmark(
    lambda nf: trees_nf[nf]['X32'],
    lambda nf: trees_nf[nf]['model'].predict_proba,
    lambda nf: (lambda x, c=nf: trees_nf[c]['oinf'].run({'X': x})), NF, N)
bench_dt_nf

Out:

  0%|          | 0/10 [00:00<?, ?it/s]
 10%|#         | 1/10 [00:00<00:00,  9.61it/s]
 20%|##        | 2/10 [00:00<00:01,  5.05it/s]
 30%|###       | 3/10 [00:00<00:02,  3.14it/s]
 40%|####      | 4/10 [00:01<00:03,  1.87it/s]
 50%|#####     | 5/10 [00:02<00:03,  1.37it/s]
 60%|######    | 6/10 [00:04<00:03,  1.01it/s]
 70%|#######   | 7/10 [00:06<00:04,  1.35s/it]
 80%|########  | 8/10 [00:10<00:04,  2.24s/it]
 90%|######### | 9/10 [00:20<00:04,  4.82s/it]
100%|##########| 10/10 [00:42<00:00,  9.94s/it]
100%|##########| 10/10 [00:42<00:00,  4.24s/it]

  0%|          | 0/10 [00:00<?, ?it/s]
 10%|#         | 1/10 [00:08<01:14,  8.31s/it]
 20%|##        | 2/10 [00:16<01:06,  8.33s/it]
 30%|###       | 3/10 [00:25<00:59,  8.44s/it]
 40%|####      | 4/10 [00:33<00:51,  8.56s/it]
 50%|#####     | 5/10 [00:42<00:43,  8.67s/it]
 60%|######    | 6/10 [00:51<00:35,  8.78s/it]
 70%|#######   | 7/10 [01:01<00:26,  8.97s/it]
 80%|########  | 8/10 [01:12<00:19,  9.81s/it]
 90%|######### | 9/10 [01:29<00:11, 11.84s/it]
100%|##########| 10/10 [01:47<00:00, 13.85s/it]
100%|##########| 10/10 [01:47<00:00, 10.74s/it]

{(1, 2): 0.5246695585404832, (10, 2): 0.5244493717457184, (100, 2): 0.5452720692326968, (1000, 2): 0.7507197963301782, (10000, 2): 1.0279234781102222, (50000, 2): 1.1028959137369485, (1, 10): 0.5205291346542287, (10, 10): 0.5195938417618414, (100, 10): 0.546481508035894, (1000, 10): 0.73668154978756, (10000, 10): 0.98386979119503, (50000, 10): 1.086355549977893, (1, 20): 0.5212294463871879, (10, 20): 0.5209435620486225, (100, 20): 0.5521858057626683, (1000, 20): 0.7375443448564826, (10000, 20): 1.0130544431715223, (50000, 20): 1.096910817372986, (1, 40): 0.5208252124169515, (10, 40): 0.519484818615285, (100, 40): 0.5464026887080339, (1000, 40): 0.7230969160615246, (10000, 40): 1.0165963377676686, (50000, 40): 1.0997984217807062, (1, 50): 0.5179792395792443, (10, 50): 0.5165388594813121, (100, 50): 0.5417924771191236, (1000, 50): 0.7045333070736611, (10000, 50): 1.0253844860897203, (50000, 50): 1.1092911701083348, (1, 70): 0.5200977548009684, (10, 70): 0.5207126782263183, (100, 70): 0.5414466469760403, (1000, 70): 0.6729904717322742, (10000, 70): 1.0296183314183227, (50000, 70): 1.1137247427488985, (1, 100): 0.5202956199677556, (10, 100): 0.5195865827705839, (100, 100): 0.5475328890385668, (1000, 100): 0.6164673839205036, (10000, 100): 1.0101236754287344, (50000, 100): 1.0807608453452566, (1, 200): 0.5202970504045829, (10, 200): 0.5193234368209779, (100, 200): 0.5370108153544751, (1000, 200): 0.6300363876840007, (10000, 200): 1.0054168546032447, (50000, 200): 1.041451894062498, (1, 500): 0.5165892916222089, (10, 500): 0.5143076098649498, (100, 500): 0.5294535913091795, (1000, 500): 0.824546373710277, (10000, 500): 1.1121528730417307, (50000, 500): 1.1539156146135665, (1, 1000): 0.5178304086993569, (10, 1000): 0.5169532504204166, (100, 1000): 0.5268868581810615, (1000, 1000): 0.8591423458247084, (10000, 1000): 1.1625350550982059, (50000, 1000): 1.205426412537513}

Graph.

plot_metric(
    bench_dt_nf, ylabel="number of features", transpose=True, figsize=(10, 4),
    title="scikit-learn vs mlprodict (DecisionTreeClassifier) \n"
    "< 1 means mlprodict is faster\n no parallelisation")
scikit-learn vs mlprodict (DecisionTreeClassifier)  < 1 means mlprodict is faster  no parallelisation

Out:

<AxesSubplot:title={'center':'scikit-learn vs mlprodict (DecisionTreeClassifier) \n< 1 means mlprodict is faster\n no parallelisation'}, xlabel='number of features', ylabel='N'>

Total running time of the script: ( 19 minutes 21.572 seconds)

Gallery generated by Sphinx-Gallery