RuleTree#

Interpretable decision trees built one node at a time, where each node can be split in a different way.

RuleTree splits each node with a stump: a threshold on a feature or on a combination of a few features, the distance from an instance of the training set (a pivot), the distance of a time series from a shapelet, which of two pivots or shapelets is closer, a fair split, … The same tree can mix different kinds of stumps and different types of data (tabular data, time series, images), and its rules can be read, drawn and saved.

Many kinds of splits

Thresholds, oblique splits, pivots, shapelets, fair splits, mixed in one tree.

Choosing the splits: stumps
Several data types

Tabular data, time series and images, together in the same tree.

Tabular data, time series and images
Rules you can read

Rules as text or drawings, node ids, contributions of the features.

Reading the tree
scikit-learn API

Classification, regression and clustering, in pipelines and grid searches.

Getting started

Quick example#

from sklearn.datasets import load_iris

from RuleTree import RuleTreeClassifier

X, y = load_iris(return_X_y=True)
model = RuleTreeClassifier(max_depth=2, random_state=0).fit(X, y)
model.print_rules(model.get_rules(columns_names=["sepal length", "sepal width",
                                                  "petal length", "petal width"]))
Output#
|--- petal width <= 0.8
|    output: 0
|--- petal width > 0.8
    |--- petal width <= 1.75
    |    output: 1
    |--- petal width > 1.75
         output: 2
from sklearn.datasets import load_diabetes

from RuleTree import RuleTreeRegressor

data = load_diabetes()
model = RuleTreeRegressor(max_depth=2, random_state=0).fit(data.data, data.target)
model.print_rules(model.get_rules(columns_names=data.feature_names))
Output#
|--- s5 <= -0.004
|   |--- bmi <= 0.006
|   |    output: 96.31
|   |--- bmi > 0.006
|        output: 159.74
|--- s5 > -0.004
    |--- bmi <= 0.015
    |    output: 162.68
    |--- bmi > 0.015
         output: 225.88
from sklearn.datasets import make_blobs

from RuleTree import RuleTreeCluster

X, _ = make_blobs(n_samples=300, centers=3, cluster_std=0.5, random_state=0)
model = RuleTreeCluster(max_depth=2, random_state=0).fit(X)
model.print_rules(model.get_rules(columns_names=["x", "y"]))
Output#
|--- y <= 1.772
|   |--- x <= -0.131
|   |    output: 3
|   |--- x > -0.131
|        output: 4
|--- y > 1.772
    |--- x <= -0.411
    |    output: 5
    |--- x > -0.411
         output: 6

Install it with pip install RuleTree (see Getting started for the optional features).

Where to go next#

Getting started

Install RuleTree and train a first tree for each task.

Getting started
How RuleTree works

Trees, nodes, stumps and their components, in one page.

How RuleTree works
User guide

Stumps, data types, rules, saving, ensembles, evaluation, extensions.

User guide
Examples

Notebooks that train a tree end to end.

Examples
API reference

Every class and function, grouped by topic.

API reference
Citing RuleTree

BibTeX entries of the library and of its papers.

Citing RuleTree