Skip to main content

Visualize decision tree in Python

Project description

SuperTree - Interactive Decision Tree Visualization

Interactive Decision Tree Visualization is a Python package designed to visualize decision trees in an interactive and user-friendly way within Jupyter Notebooks, Jupyter Lab, Google Colab, and any other notebooks that support HTML rendering.

Description

This package allows users to seamlessly integrate decision tree visualizations into their data analysis workflows. With this tool, you can not only display decision trees, but also interact with them directly within your notebook environment.

Key features

Whether you're presenting your analysis to others or exploring complex models yourself, this package enhances the way you work with decision trees by making them more accessible and easier to understand. Key features include:

  • ability to zoom and pan through large trees,
  • collapse and expand selected nodes,
  • explore the structure of the tree in an intuitive and visually appealing manner.

Instalation

You can install SuperTree package using pip:

pip install supertree

Conda support coming soon.

Supported Libraries

  • scikit-learn (sklearn)
  • LightGBM
  • XGBoost

Supported Algorithms

The package is compatible with a wide range of classifiers and regressors from these libraries, specifically:

Scikit-learn

  • DecisionTreeClassifier
  • ExtraTreeClassifier
  • ExtraTreesClassifier
  • RandomForestClassifier
  • GradientBoostingClassifier
  • DecisionTreeRegressor
  • ExtraTreeRegressor
  • ExtraTreesRegressor
  • RandomForestRegressor
  • GradientBoostingRegressor

LightGBM

  • LGBMClassifier
  • LGBMRegressor
  • Booster

XGBoost

  • XGBClassifier
  • XGBRFClassifier
  • XGBRegressor
  • XGBRFRegressor
  • Booster

If we do not support the model you want to use, please let us know.

Examples

Decision Tree classifier on iris data.

from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris
from supertree import SuperTree # <- import supertree :)

# Load the iris dataset
iris = load_iris()
X, y = iris.data, iris.target

# Train model
model = DecisionTreeClassifier()
model.fit(X, y)

# Initialize supertree
super_tree = SuperTree(model, X, y, iris.feature_names, iris.target_names)

# show tree in your notebook
super_tree.show_tree()

Random Forest Regressor Example

from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import load_diabetes
from supertree import SuperTree  # <- import supertree :)

# Load the diabetes dataset
diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target

# Train model
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Initialize supertree
super_tree = SuperTree(model,X, y)
# show tree with index 2 in your notebook
super_tree.show_tree(2)

There are more code snippets in the examples directory.

Support

If you encounter any issues, find a bug, or have a feature request, we would love to hear from you! Please don't hesitate to reach out to us at supertree/issues. We are committed to improving this package and appreciate any feedback or suggestions you may have.

License

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

supertree-0.1.0.tar.gz (152.7 kB view details)

Uploaded Source

File details

Details for the file supertree-0.1.0.tar.gz.

File metadata

  • Download URL: supertree-0.1.0.tar.gz
  • Upload date:
  • Size: 152.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for supertree-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2b78701fa4eb19ce0dd6a7469adcb3301a8ea2f55bfd9e7073b94e1e0cb8b36f
MD5 a5f17967adc265ec0246050aef279d46
BLAKE2b-256 92356796a1c0396521444ca33788aab3ea2f0788d9f5c9b11e6cf2da55abaaa9

See more details on using hashes here.

Supported by

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