跳转到主要内容

Python中的现代决策树

项目描述

Code style: black CircleCI Main Checked with mypy codecov PyPI Download count Latest PyPI release DOI

treeple

treeple是一个用于构建最先进决策树的scikit-learn兼容API。这些包括无监督树、斜树、不确定性树、分位数树和因果树。

树模型经受了时间的考验,并且一直被用于现代数据科学和机器学习应用。当问题样本有限时,它们表现尤为出色,并且是灵活的学习者,可以应用于各种不同的设置,例如表格、图像、时间序列、基因组学、EEG数据等。

请注意,此包最初命名为scikit-tree,但在0.8.0版本后更名为treeple。版本 <0.8.0 仍在https://pypi.ac.cn/project/scikit-tree/上提供。

文档

请在此处查看我们开发版本的文档:https://docs.neurodata.io/treeple/dev/index.html

为什么要使用斜切树,以及为什么要在scikit-learn之外的树上使用树?

2001年,Leo Breiman提出了两种随机森林。一种被称为Forest-RI,这是轴对齐的传统随机森林。另一种被称为Forest-RC,这是随机斜切线性组合随机森林。它利用特征的随机组合来执行分割。《MORF》在Forest-RC的基础上,通过提出额外的组合特征函数。其他现代树变体,如典型相关森林(CCF)、扩展隔离森林、分位数森林或无监督随机森林,在解决现实世界问题中使用鲁棒的决策树模型方面也非常重要。

安装

我们的安装将尽可能遵循scikit-learn的安装,因为我们包含Cython代码子类,或受scikit-learn树子模块的启发。

依赖项

我们至少需要

* Python (>=3.9)
* numpy
* scipy
* scikit-learn >= 1.3

使用Pip安装(https://pypi.ac.cn/project/treeple/

在conda环境中使用pip安装是推荐的方法。

pip install treeple

使用Meson本地构建(开发者)

确保您已安装必要的软件包

# install build dependencies
pip install -r build_requirements.txt

# you may need these optional dependencies to build scikit-learn locally
conda install -c conda-forge joblib threadpoolctl pytest compilers llvm-openmp

我们使用spin CLI来抽象构建细节

# run the build using Meson/Ninja
./spin build

# you can run the following command to see what other options there are
./spin --help
./spin build --help

# For example, you might want to start from a clean build
./spin build --clean

# or build in parallel for faster builds
./spin build -j 2

# you will need to double check the build-install has the proper path
# this might be different from machine to machine
export PYTHONPATH=${PWD}/build-install/usr/lib/python3.9/site-packages

# run specific unit tests
./spin test -- treeple/tree/tests/test_tree.py

# you can bring up the CLI menu
./spin --help

您也可以使用Meson/Ninja本身做同样的事情。运行以下命令以构建本地文件

# generate ninja make files
meson build --prefix=$PWD/build

# compile
ninja -C build

# install treeple package
meson install -C build

export PYTHONPATH=${PWD}/build/lib/python3.9/site-packages

# to check installation, you need to be in a different directory
cd docs;  
python -c "from treeple import tree"
python -c "import sklearn; print(sklearn.__version__);"

本地构建完成后,您可以使用可编辑的安装(警告:这仅在本地上注册Python更改)

pip install --no-build-isolation --editable .

或者如果您已安装spin v0.8+,可以直接运行

spin install

开发

我们欢迎对现代基于树的算法的贡献。我们使用Cython实现快速的C/C++速度,同时遵守与scikit-learn兼容的(测试过的)API。此外,我们的Cython内部易于扩展,因为它们遵循scikit-learn的内部Cython API。

由于scikit-learn当前树内部Cython代码的状态,当我们扩展scikit-learn的决策树模型API时,我们不得不利用scikit-learn的分支https://github.com/neurodata/scikit-learn。具体来说,我们在子模块中扩展了scikit-learn中树子模块的Python和Cython API,以便我们可以引入本包中包含的树模型。因此,这些扩展了决策树模型的函数,这在scikit-learn本身中尚不可行。例如,我们引入了一个抽象API,允许用户实现自己的斜切分割。我们的计划是在未来对这些功能进行基准测试,并将它们引入scikit-learn,前提是适用且满足纳入标准。

参考文献

[1]: Li, Adam, et al. "Manifold Oblique Random Forests: Towards Closing the Gap on Convolutional Deep Networks" SIAM Journal on Mathematics of Data Science, 5(1), 77-96, 2023

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分布

treeple-0.9.1.tar.gz (15.4 MB 查看散列值)

上传时间:

构建分布

treeple-0.9.1-cp312-cp312-win_amd64.whl (4.9 MB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

treeple-0.9.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

treeple-0.9.1-cp312-cp312-macosx_11_0_arm64.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.12 macOS 11.0+ ARM64

treeple-0.9.1-cp312-cp312-macosx_10_9_x86_64.whl (2.2 MB 查看哈希值)

上传时间 CPython 3.12 macOS 10.9+ x86-64

treeple-0.9.1-cp311-cp311-win_amd64.whl (5.0 MB 查看哈希值)

上传时间 CPython 3.11 Windows x86-64

treeple-0.9.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB 查看哈希值)

上传时间 CPython 3.11 manylinux: glibc 2.17+ x86-64

treeple-0.9.1-cp311-cp311-macosx_11_0_arm64.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.11 macOS 11.0+ ARM64

treeple-0.9.1-cp311-cp311-macosx_10_9_x86_64.whl (2.2 MB 查看哈希值)

上传时间 CPython 3.11 macOS 10.9+ x86-64

treeple-0.9.1-cp310-cp310-win_amd64.whl (5.0 MB 查看哈希值)

上传时间 CPython 3.10 Windows x86-64

treeple-0.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB 查看哈希值)

上传时间 CPython 3.10 manylinux: glibc 2.17+ x86-64

treeple-0.9.1-cp310-cp310-macosx_11_0_arm64.whl (2.0 MB 查看哈希)

上传于 CPython 3.10 macOS 11.0+ ARM64

treeple-0.9.1-cp310-cp310-macosx_10_9_x86_64.whl (2.2 MB 查看哈希)

上传于 CPython 3.10 macOS 10.9+ x86-64

treeple-0.9.1-cp39-cp39-win_amd64.whl (5.0 MB 查看哈希)

上传于 CPython 3.9 Windows x86-64

treeple-0.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB 查看哈希)

上传于 CPython 3.9 manylinux: glibc 2.17+ x86-64

treeple-0.9.1-cp39-cp39-macosx_11_0_arm64.whl (2.0 MB 查看哈希)

上传于 CPython 3.9 macOS 11.0+ ARM64

treeple-0.9.1-cp39-cp39-macosx_10_9_x86_64.whl (2.2 MB 查看哈希)

上传于 CPython 3.9 macOS 10.9+ x86-64

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面