Skip to main content

Scikit-Learn Compiled Trees

Build Status PyPI

Installation

Released under the MIT License.

pip install sklearn-compiledtrees

Rationale

In some use cases, predicting given a model is in the hot-path, so speeding up decision tree evaluation is very useful.

An effective way of speeding up evaluation of decision trees can be to generate code representing the evaluation of the tree, compile that to optimized object code, and dynamically load that file via dlopen/dlsym or equivalent.

See https://courses.cs.washington.edu/courses/cse501/10au/compile-machlearn.pdf for a detailed discussion, and http://tullo.ch/articles/decision-tree-evaluation/ for a more pedagogical explanation and more benchmarks in C++.

This package implements compiled decision tree evaluation for the simple case of a single-output regression tree or ensemble.

It has been tested to work on both OS X and Linux. We do not currently support Windows platforms for compiled evaluation, although this should not be a signficant amount of work.

Usage

import compiledtrees
import sklearn.ensemble

X_train, y_train, X_test, y_test = ...

clf = ensemble.GradientBoostingRegressor()
clf.fit(X_train, y_train)

compiled_predictor = compiledtrees.CompiledRegressionPredictor(clf)
predictions = compiled_predictor.predict(X_test)

Benchmarks

For random forests, we see 5x to 8x speedup in evaluation. For gradient boosted ensembles, it’s between a 1.5x and 3x speedup in evaluation. This is due to the fact that gradient boosted trees already have an optimized prediction implementation.

There is a benchmark script attached that allows us to examine the performance of evaluation across a range of ensemble configurations and datasets.

In the graphs attached, GB is Gradient Boosted, RF is Random Forest, D1, etc correspond to setting max-depth=1, and B10 corresponds to setting max_leaf_nodes=10.

Graphs

for dataset in friedman1 friedman2 friedman3 uniform hastie; do
    python ../benchmarks/bench_compiled_tree.py \
        --iterations=10 \
        --num_examples=1000 \
        --num_features=50 \
        --dataset=$dataset \
        --max_estimators=300 \
        --num_estimator_values=6
done

timings3907426606273805268 timings-1162001441413946416 timings5617004024503483042 timings2681645894201472305 timings2070620222460516071

Metadata

Release files for sklearn-compiledtrees 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sklearn-compiledtrees 1.2
File Size Uploaded Provenance
sklearn-compiledtrees-1.2.tar.gz 46.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sklearn-compiledtrees 1.2
File Interpreter ABI Platform
sklearn-compiledtrees-1.2.macosx-10.9-x86_64.tar.gz Details

Total release size: 76.8 kB

Release files / sklearn-compiledtrees-1.2.tar.gz

Download URL sklearn-compiledtrees-1.2.tar.gz
Size 46.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c35d02bd2963ac3c78da5a8c4d8e17fb59630f4301fbd7f3d8fd88054b5d0f5e
BLAKE2b-256 checksum
How to use checksums
fa18a473b0d5bdd7d2fc015fc6a121a17a91d2b97f1ff39b308bbb128a8e6921
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sklearn-compiledtrees-1.2.macosx-10.9-x86_64.tar.gz

Download URL sklearn-compiledtrees-1.2.macosx-10.9-x86_64.tar.gz
Size 30.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a09a478e46f616f125f8d12cd3c85524df1727bbfee1dd6a6e95b87941f4d06f
BLAKE2b-256 checksum
How to use checksums
4071777580818558cbccac4394890ee785b20011aa1915373b48e948dd81022c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for sklearn-compiledtrees 1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files No provenance

1.0.2

1.0.1

1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page