Skip to main content

Python package treeplot vizualizes a tree based on a randomforest or xgboost model.

Project description

treeplot

Python PyPI Version License Downloads Donate

  • 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. One of the most popular and classical explainable models the tree based, such as 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!

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)

# If you have more parameters to specify:
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)

# If you have more parameters to specify:
ax = treeplot.xgboost(model, plottype='vertical')

Maintainers

Contribute

  • Contributions are welcome.

Licence

See LICENSE for details.

Donation

  • This work is created and maintained in my free time. If you wish to buy me a Coffee for this work, it is very appreciated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

treeplot-0.1.8.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

treeplot-0.1.8-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file treeplot-0.1.8.tar.gz.

File metadata

  • Download URL: treeplot-0.1.8.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0.post20200127 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for treeplot-0.1.8.tar.gz
Algorithm Hash digest
SHA256 af8a36a388e41614dd497d5aa13695861be54473266a5e2e8d3b98a7444ce860
MD5 cfe59544e7f7331393dd4780fd0ded4a
BLAKE2b-256 4499ad72021e784e181dae60ccfc55084f2ba64152fb2136d9ddf029f9c00ab0

See more details on using hashes here.

File details

Details for the file treeplot-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: treeplot-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0.post20200127 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for treeplot-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 def9344ed2ffeeb59539894d3bc9d98357cb8381f4eafdab36bae501ecca858a
MD5 5a45607014a5ff498d94bcbbaa7ea31f
BLAKE2b-256 4792ad1f2ad88a4c22bc613127a4ff5d565e68d781774fad1eed9fd4728d41f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page