skip to navigation
skip to content

sklearn-compiledtrees 1.0.5

Compiled scikit-learn decision trees for faster evaluation

Latest Version: 1.2


pip install sklearn-compiledtrees


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 for a detailed discussion, and 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.


import compiledtrees
import sklearn.ensemble

X_train, y_train, X_test, y_test = ...

clf = ensemble.GradientBoostingRegressor(), y_train)

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


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.


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

File Type Py Version Uploaded on Size
sklearn-compiledtrees-1.0.5.macosx-10.8-x86_64.tar.gz (md5)
built for Darwin-13.1.0
"dumb" binary 2.7 2014-03-28 29KB
sklearn-compiledtrees-1.0.5.tar.gz (md5) Source 2014-03-28 45KB
  • Downloads (All Versions):
  • 7 downloads in the last day
  • 140 downloads in the last week
  • 820 downloads in the last month