A simple interface to modify scikit-learn's generated DOT representation of a decision tree.
Project description
DrawScikitTree
A simple interface to modify scikit-learn's generated DOT string representation of a trained decision tree. Some basic function include changing the shape and color of each node, and tracing the decision paths taken for a test sample.
Installation
pip install draw-scikit-tree
Basic usage
Using the iris dataset as the classical example.
from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
X, y = iris.data, iris.target
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)
Next, use the trained classifier to initialize the TreeGraph object.
from DrawScikitTree import TreeGraph
treeGraph = TreeGraph(clf, impurity=False, label="none", fontname="Arial")
To trace the decisions paths taken for some test samples, use the .trace_paths(X_sample) function.
import numpy as np
import graphviz
# Get some random samples
random_indices = np.random.randint(X.shape[0], size=5)
X_sample = X[random_indices, :]
# Setting verbose=True will print out the decision paths for each sample
treeGraph.trace_paths(X_sample, color="red", verbose=True)
# Displaying the newly modified tree
new_dot_data = treeGraph.export()
graph = graphviz.Source(new_dot_data)
display(graph)
For more examples check out the examples.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file draw_scikit_tree-0.1.4.tar.gz.
File metadata
- Download URL: draw_scikit_tree-0.1.4.tar.gz
- Upload date:
- Size: 255.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dc661cd629b57289c3c5c729daabbd3c71299a23655243a0e053da41cb3d625
|
|
| MD5 |
a5eafaea767b90bce03a2cd554b85540
|
|
| BLAKE2b-256 |
d7081c51af5b3c5b1a34ce073a0c852016a3f34a95f7289aefa99397d62bb82f
|
File details
Details for the file draw_scikit_tree-0.1.4-py3-none-any.whl.
File metadata
- Download URL: draw_scikit_tree-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b59fa12ffc2df042dce6f308f273dca0415658e4b67441084e35f78295bd3eb5
|
|
| MD5 |
6c7ed9f6d3b49fe6319abd7fa3ea60bb
|
|
| BLAKE2b-256 |
694e729be57396c198fb801bd65029f42683bed2358844f32eaf576e372fd6e1
|