adam2392 / scikit-tree-fork

Scikit-learn compatible decision trees beyond those offered in scikit-learn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code style: black CircleCI Main Checked with mypy codecov

scikit-tree

scikit-tree is a scikit-learn compatible API for building state-of-the-art decision trees. These include unsupervised trees, oblique trees, uncertainty trees, quantile trees and causal trees.

History of oblique trees

In 2001, Leo Breiman proposed two types of Random Forests. One was known as Forest-RI, which is the axis-aligned traditional random forest. One was known as Forest-RC, which is the random oblique linear combinations random forest. This leveraged random combinations of features to perform splits. MORF builds upon Forest-RC by proposing additional functions to combine features.

Installation

Our installation will try to follow scikit-learn installation as close as possible, as we contain Cython code subclassed, or inspired by the scikit-learn tree submodule.

Building locally with Meson

Make sure you have the necessary packages installed

# install general package dependencies
poetry install --with style,test,docs

# install build dependencies
pip install meson ninja meson-python Cython scikit-learn numpy

Run the following to build the local files

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

# compile
ninja -C build

# install scikit-tree package
meson install -C build

# 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__);"

You can also do the same thing using the dev.py CLI:

# run the build using Meson/Ninja
./dev.py build

# run specific unit tests
./dev.py test -- sktree/tree/tests/test_tree.py

Conda (Recommended)

First, create a virtual environment using Conda.

conda create -n sklearn-dev python=3.9

activate the virtual environment and install necessary packages to build from source

conda activate sklearn-dev
conda install -c conda-forge numpy scipy cython joblib threadpoolctl pytest compilers llvm-openmp poetry

Next, sktree from source:

pip install -e .

# if editing Cython files
pip install --verbose --no-build-isolation --editable .

To install the package from github, clone the repository and then cd into the directory. You can then use poetry to install:

poetry install

# if you would like an editable install of dodiscover for dev purposes
pip install -e .

pip install https://api.github.com/repos/neurodata/scikit-tree/zipball/main


pip install https://api.github.com/repos/neurodata/scikit-learn/zipball/obliquepr

Note that currently, we need to build the development version of scikit-learn with oblique trees within this PR.

Checkout this PR code, and build from source, using scikit-learn's build from source page instructions.

Alpha Functionality

We can impose a Gabor or wavelet filter bank. To do so, install skimage and pywavelets.

pip install scikit-image
pip install PyWavelets

Using with Jupyter Notebook

To setup an ipykernel with jupyter notebook, then do:

python -m ipykernel install --name sklearn --user 

About

Scikit-learn compatible decision trees beyond those offered in scikit-learn

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Jupyter Notebook 94.0%Language:Python 2.9%Language:Cython 2.9%Language:Meson 0.2%