Skip to main content

A simple interface to modify scikit-learn's generated DOT representation of a decision tree.

Project description

DrawScikitTreeLogo

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)
ExampleTree

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

draw_scikit_tree-0.1.5.tar.gz (255.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

draw_scikit_tree-0.1.5-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file draw_scikit_tree-0.1.5.tar.gz.

File metadata

  • Download URL: draw_scikit_tree-0.1.5.tar.gz
  • Upload date:
  • Size: 255.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.13

File hashes

Hashes for draw_scikit_tree-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3f43fb772964a1267fc1177f9b1e48c5f7f99ec8e6efd555cfb677f82b162ae6
MD5 fb0da787d1331ef841d4586855091069
BLAKE2b-256 6db4cc03ed24b45e3a992a57696c14e42dff7c2453e052fdc1add477d013e40d

See more details on using hashes here.

File details

Details for the file draw_scikit_tree-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for draw_scikit_tree-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b106068525264241c87ec09bdcdd1bade0470ddb2bf19e8c59f238dc7c7c193f
MD5 ed90962de87f25f5b4e5cb0aa765dc1d
BLAKE2b-256 7c6e21f0395696ab91c0e52446b9c2efc1d2fe9fdf3823e9fbdeed0342f29595

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