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.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.

Metadata

Release files for treeplot 0.1.14

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.14
File Size Uploaded Provenance Actions
treeplot-0.1.14.tar.gz 7.4 kB Without provenance Details for treeplot-0.1.14.tar.gz

Built distribution (wheel)

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

Total release size: 15.9 kB

Release files / treeplot-0.1.14.tar.gz

Download URL treeplot-0.1.14.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8ee451ec09de924f8fdfbe4e67b232df6699314485a601c1311593155dfd09df
BLAKE2b-256 checksum
How to use checksums
d28881359385cbab22cbdf46a2ef72efe8eee59715b7634eb565aa932bd1f4c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2.post20210112 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

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

Download URL treeplot-0.1.14-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
988341b72975e9c2393ca746abb89f981c391497063754d440f75721ec59dc0d
BLAKE2b-256 checksum
How to use checksums
a8987e567a055a2c801fb39df7b9c3841d82548a8db21b57259035433d45cc29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2.post20210112 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.12

Security for treeplot 0.1.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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