跳转到主要内容

Python中的现代决策树

项目描述

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

scikit-tree

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

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

文档

有关我们开发版本的文档,请参阅此处:https://docs.neurodata.io/scikit-tree/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/scikit-tree/

在conda环境中使用pip安装是推荐的路线。

pip install scikit-tree

使用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 -- sktree/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 scikit-tree 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 sktree 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

项目详情


下载文件

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

源代码发行版

scikit_tree-0.8.0.tar.gz (15.4 MB 查看散列值)

上传时间 源代码

构建发行版

scikit_tree-0.8.0-cp312-cp312-win_amd64.whl (4.9 MB 查看散列值)

上传时间 CPython 3.12 Windows x86-64

scikit_tree-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB 查看散列值)

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

scikit_tree-0.8.0-cp312-cp312-macosx_11_0_arm64.whl (2.0 MB 查看哈希值)

上传于 CPython 3.12 macOS 11.0+ ARM64

scikit_tree-0.8.0-cp312-cp312-macosx_10_9_x86_64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.12 macOS 10.9+ x86-64

scikit_tree-0.8.0-cp311-cp311-win_amd64.whl (5.0 MB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

scikit_tree-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB 查看哈希值)

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

scikit_tree-0.8.0-cp311-cp311-macosx_11_0_arm64.whl (2.0 MB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

scikit_tree-0.8.0-cp311-cp311-macosx_10_9_x86_64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.11 macOS 10.9+ x86-64

scikit_tree-0.8.0-cp310-cp310-win_amd64.whl (5.0 MB 查看哈希值)

上传于 CPython 3.10 Windows x86-64

scikit_tree-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB 查看哈希值)

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

scikit_tree-0.8.0-cp310-cp310-macosx_11_0_arm64.whl (2.0 MB 查看哈希值)

上传于 CPython 3.10 macOS 11.0+ ARM64

scikit_tree-0.8.0-cp310-cp310-macosx_10_9_x86_64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.10 macOS 10.9+ x86-64

scikit_tree-0.8.0-cp39-cp39-win_amd64.whl (5.0 MB 查看哈希值)

上传于 CPython 3.9 Windows x86-64

scikit_tree-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB 查看哈希值)

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

scikit_tree-0.8.0-cp39-cp39-macosx_11_0_arm64.whl (2.0 MB 查看哈希值)

上传于 CPython 3.9 macOS 11.0+ ARM64

scikit_tree-0.8.0-cp39-cp39-macosx_10_9_x86_64.whl (2.2 MB 查看哈希值)

上传于 CPython 3.9 macOS 10.9+ x86-64

支持者: