{"id":13937486,"url":"https://github.com/ajtulloch/sklearn-compiledtrees","last_synced_at":"2026-01-05T05:57:58.174Z","repository":{"id":15158270,"uuid":"17885881","full_name":"ajtulloch/sklearn-compiledtrees","owner":"ajtulloch","description":"Compiled Decision Trees for scikit-learn","archived":false,"fork":false,"pushed_at":"2024-05-14T07:44:02.000Z","size":273,"stargazers_count":223,"open_issues_count":3,"forks_count":37,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-12-16T21:48:30.211Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"tullo.ch/articles/decision-tree-evaluation/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajtulloch.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-18T23:40:08.000Z","updated_at":"2024-11-28T16:28:59.000Z","dependencies_parsed_at":"2024-11-27T06:43:42.833Z","dependency_job_id":null,"html_url":"https://github.com/ajtulloch/sklearn-compiledtrees","commit_stats":{"total_commits":57,"total_committers":6,"mean_commits":9.5,"dds":0.6140350877192983,"last_synced_commit":"7f24f3f57827f4cc22fb1be065ee44838d3ba605"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajtulloch%2Fsklearn-compiledtrees","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajtulloch%2Fsklearn-compiledtrees/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajtulloch%2Fsklearn-compiledtrees/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajtulloch%2Fsklearn-compiledtrees/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajtulloch","download_url":"https://codeload.github.com/ajtulloch/sklearn-compiledtrees/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232479963,"owners_count":18530037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-07T23:03:37.278Z","updated_at":"2026-01-05T05:57:58.155Z","avatar_url":"https://github.com/ajtulloch.png","language":"Python","funding_links":[],"categories":["Python","Deployment"],"sub_categories":["Ranking/Recommender"],"readme":"Scikit-Learn Compiled Trees\n===========================\n\n|Build Status|\n|PyPI|\n\nInstallation\n------------\n\nReleased under the MIT License.\n\n.. code:: bash\n\n    pip install sklearn-compiledtrees\n\nOr to get the latest development version:\n\n.. code:: bash\n\n    pip install git+https://github.com/ajtulloch/sklearn-compiledtrees.git\n\nsklearn-compiledtrees has been tested to work on OS X, Linux and Windows.\n\nInstalling on Windows requires GCC compiler and dlfcn-win32_,\nsetting `CXX` environment variable (`set \"CXX=gcc -pthread\"` for CMD),\nand manual installation from source directory. Using msys2 distribution in conda\nis strongly recommended.\n\n.. code:: bash\n    conda install -c msys2 m2w64-toolchain m2w64-dlfcn pywin32\n    python setup.py build_ext --compiler=mingw32 -llibdl\n    python setup.py install\n\n\nRationale\n---------\n\nIn some use cases, predicting given a model is in the hot-path, so\nspeeding up decision tree evaluation is very useful.\n\nAn effective way of speeding up evaluation of decision trees can be to\ngenerate code representing the evaluation of the tree, compile that to\noptimized object code, and dynamically load that file via dlopen/dlsym\nor equivalent.\n\nSee\nhttps://courses.cs.washington.edu/courses/cse501/10au/compile-machlearn.pdf\nfor a detailed discussion, and\nhttp://tullo.ch/articles/decision-tree-evaluation/ for a more\npedagogical explanation and more benchmarks in C++.\n\nThis package implements compiled decision tree evaluation for the simple\ncase of a single-output regression tree or ensemble.\n\n\nUsage\n-----\n\n.. code:: python\n\n    import compiledtrees\n    import sklearn.ensemble\n\n    X_train, y_train, X_test, y_test = ...\n\n    clf = ensemble.GradientBoostingRegressor()\n    clf.fit(X_train, y_train)\n\n    compiled_predictor = compiledtrees.CompiledRegressionPredictor(clf)\n    predictions = compiled_predictor.predict(X_test)\n\nBenchmarks\n----------\n\nFor random forests, we see 5x to 8x speedup in evaluation. For gradient\nboosted ensembles, it's between a 1.5x and 3x speedup in evaluation.\nThis is due to the fact that gradient boosted trees already have an\noptimized prediction implementation.\n\nThere is a benchmark script attached that allows us to examine the\nperformance of evaluation across a range of ensemble configurations and\ndatasets.\n\nIn the graphs attached, ``GB`` is Gradient Boosted, ``RF`` is Random\nForest, ``D1``, etc correspond to setting ``max-depth=1``, and ``B10``\ncorresponds to setting ``max_leaf_nodes=10``.\n\nGraphs\n------\n\n.. code:: bash\n\n    for dataset in friedman1 friedman2 friedman3 uniform hastie; do\n        python ../benchmarks/bench_compiled_tree.py \\\n            --iterations=10 \\\n            --num_examples=1000 \\\n            --num_features=50 \\\n            --dataset=$dataset \\\n            --max_estimators=300 \\\n            --num_estimator_values=6\n    done\n\n|timings3907426606273805268| |timings-1162001441413946416|\n|timings5617004024503483042| |timings2681645894201472305|\n|timings2070620222460516071|\n\n.. |Build Status| image:: https://travis-ci.org/ajtulloch/sklearn-compiledtrees.png?branch=master\n   :target: https://travis-ci.org/ajtulloch/sklearn-compiledtrees\n\n.. |PyPI| image:: https://badge.fury.io/py/sklearn-compiledtrees.png\n   :target: http://badge.fury.io/py/sklearn-compiledtrees\n\n.. _dlfcn-win32: https://github.com/dlfcn-win32/dlfcn-win32\n\n.. |timings3907426606273805268| image:: https://f.cloud.github.com/assets/1121581/2453407/c70a64bc-aedd-11e3-94c7-519411ae6276.png\n   :width: 500px\n.. |timings-1162001441413946416| image:: https://f.cloud.github.com/assets/1121581/2453409/c70ad4ec-aedd-11e3-972d-07a49a6bc610.png\n   :width: 500px\n.. |timings5617004024503483042| image:: https://f.cloud.github.com/assets/1121581/2453410/c70b48dc-aedd-11e3-9c68-ec3f9d4672b8.png\n   :width: 500px\n.. |timings2681645894201472305| image:: https://f.cloud.github.com/assets/1121581/2453411/c70b4de6-aedd-11e3-86bd-d534b0ad0618.png\n   :width: 500px\n.. |timings2070620222460516071| image:: https://f.cloud.github.com/assets/1121581/2453408/c70aa594-aedd-11e3-8b14-1a26eb1f3eba.png\n   :width: 500px\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajtulloch%2Fsklearn-compiledtrees","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajtulloch%2Fsklearn-compiledtrees","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajtulloch%2Fsklearn-compiledtrees/lists"}