-1

I working on a draw decision tree with python,

tree.plot_tree(clf.fit(X_train, y_train))
plt.suptitle("Decision surface of a decision tree using paired features")
plt.show()

but when I run this code, the tree shows up like this

Decision Tree

Is there any possible way to make the tree normal?

1
  • Have you tried changing some options, such as font size? Commented Oct 30, 2019 at 20:58

2 Answers 2

1

export_graphviz might be a good alternative for you.

Here is a Kaggle notebook that explains how to make the best use of this functionality provided by sklearn.

For the plot_tree function you are using you can try changing the font size using the fontsize argument. Or you can also try changing the size of the figure if you haven't already done that by doing something like this -

fig = matplotlib.pyplot.gcf()
fig.set_size_inches(x, y) #dimensions you want
Sign up to request clarification or add additional context in comments.

Comments

0

Here is my code in which I use the iris dataset to draw the decision tree I hope it can help you.

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier, export_graphviz
import graphviz

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

# Create a decision tree classifier
clf = DecisionTreeClassifier()

# Train the classifier
clf.fit(X, y)

# Visualize the decision tree
dot_data = export_graphviz(clf, out_file=None, 
                           feature_names=iris.feature_names,  
                           class_names=iris.target_names,  
                           filled=True, rounded=True,  
                           special_characters=True)  
graph = graphviz.Source(dot_data)  
graph.render("iris_decision_tree", format='png', cleanup=True)

# Display the decision tree
graph.view()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.