Skip to main content

treeplot

Python PyPI Version License Downloads Downloads

  • treeplot is Python package to easily plot the tree derived from models such as decisiontrees, randomforest and xgboost. Developing explainable machine learning models is becoming more important in many domains. The most popular and classical explainable models are still tree based. Think of decision trees or random forest. The tree that is learned can be visualized and then explained. However, it can be a challange to simply plot the tree. Think of configuration issues with dot files, path locations to graphviz, differences across operating systems, differences across editors such as jupyter notebook, colab, spyder etc. This frustration led to this library, an easy way to plot the decision trees 🌲. It works for Random-forest, decission trees, xgboost and gradient boosting models. Under the hood it makes many checks, downloads graphviz, sets the path and then plots the tree.

Have fun!

Functions in treeplot

Treeplot can plot the tree for Random-forest, decission trees, xgboost and gradient boosting models:

  • treeplot.plot() : Generic function to plot the tree of any of the four models with default settings
  • treeplot.plot_tree() : Plot the decission tree model. Parameters can be specified.
  • treeplot.randomforest() : Plot the randomforest model. Parameters can be specified.
  • treeplot.xgboost() : Plot the xgboost model. Parameters can be specified.
  • treeplot.import_example('iris') : Import example dataset

Contents

Installation

  • Install treeplot from PyPI (recommended). treeplot is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.
  • It is distributed under the MIT license.

Quick Start

pip install treeplot
  • Alternatively, install treeplot from the GitHub source:
git clone https://github.com/erdogant/treeplot.git
cd treeplot
python setup.py install

Import treeplot package

import treeplot

Example RandomForest:

# Load example dataset
X,y = treeplot.import_example()
# Learn model
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0).fit(X, y)
# Make plot
ax = treeplot.plot(model)
# or directly
ax = treeplot.randomforest(model)

# If more parameters needs to be specified, use the exact function:
ax = treeplot.randomforest(model, export='pdf')

Example XGboost:

# Load example dataset
X,y = treeplot.import_example()
# Learn model
from xgboost import XGBClassifier
model = XGBClassifier(n_estimators=100, max_depth=2, random_state=0).fit(X, y)
# Make plot
ax = treeplot.plot(model)
# or directly
ax = treeplot.xgboost(model)

# If more parameters needs to be specified, use the exact function:
ax = treeplot.xgboost(model, plottype='vertical')

Maintainers

Contribute

  • Contributions are welcome.

Licence

See LICENSE for details.

Release files for treeplot 0.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treeplot 0.1.11
File Size Uploaded
treeplot-0.1.11.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for treeplot 0.1.11
File Interpreter ABI Platform
treeplot-0.1.11-py3-none-any.whl Python 3 none any Details

Total release size:15.5 kB

Release files / treeplot-0.1.11.tar.gz

Download URL treeplot-0.1.11.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c1f086884ffcbb6aea9988b7ed04e7145dca7bc1d214f811869ea8f113cbd324
BLAKE2b-256 checksum
How to use checksums
2535043b509f91cc1ca69fbe4524ad058eb89b4c21b58ea79f57aca2f6b4a8f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / treeplot-0.1.11-py3-none-any.whl

Download URL treeplot-0.1.11-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a5ff082e76526ea3ae38b3ea245693981ae5ee6993f57a73d28390d8fe8391f
BLAKE2b-256 checksum
How to use checksums
a38b9599f4be7e109ce7e2e480abd07442a0e2fade5395e1ecba3ee4e1423390
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

This release

0.1.11 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page