Visualize decision tree in Python
Project description
supertree
- Interactive Decision Tree Visualization
supertree
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. With this tool, you can not only display decision trees, but also interact with them directly within your notebook environment. 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.
Features
See all the details |
Zoom |
Fullscreen in Jupyter |
Depth change |
Color change |
Navigate in forest |
Show specific sample path |
Save tree to svg |
Links sample visualization |
Showing the path to the leaf |
Check this features in example directory :)
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, max_depth=3, random_state=42)
model.fit(X, y)
# 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.
Instalation
You can install SuperTree package using pip:
pip install supertree
Conda support coming soon.
Supported Libraries
- scikit-learn (
sklearn
) - LightGBM
- XGBoost
- ONNX:
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
HistGradientBoostingClassifier
DecisionTreeRegressor
ExtraTreeRegressor
ExtraTreesRegressor
RandomForestRegressor
GradientBoostingRegressor
HistGradientBoostingRegressor
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.
Articles
- Visualize decision tree from scikit-learn package
- 4 ways to vizualize decision tree from LightGBM
- How to visualize decision tree from Xgboost
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
supertree
is a commercial software with two licenses available:
- AGPL-3.0 license
- Commercial license with support and maintenance included. Pricing website https://mljar.com/supertree/ License supertree-commercial-license.pdf.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file supertree-0.5.3.tar.gz
.
File metadata
- Download URL: supertree-0.5.3.tar.gz
- Upload date:
- Size: 321.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c8ba7fad02241d3913145e2c9e862815445c3a855867282be019bca2a1e41f0 |
|
MD5 | aa8d6a797d4f6a59eabf9aec355fe5ab |
|
BLAKE2b-256 | 04171cee3cef4b40416c3c22926795594cb63d812e9782f575d76c0f9f6f7429 |