Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display high resolution picture of the decision tree in Python?

Am using the following code to extract rules. Please help me plot a tree of higher resolution as the image gets blurred when I increase the tree depth.

from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
classifier = DecisionTreeClassifier(max_depth = 3,random_state = 0)
tree.plot_tree(classifier);

Also, how can I extract rule from a random Forest Classifier.

Also are there

like image 678
Deeksha Mahapatra Avatar asked Oct 30 '25 11:10

Deeksha Mahapatra


1 Answers

I'd just save the plot to a PDF file and use that to zoom in to whichever part you want

just put plt.savefig('out.pdf') after your call to plot_tree and matplotlib should do the right thing

note that any "vector" image format will do the right thing here, so a svg file would also be a fine choice as image editors tend to support zooming more nicelyer

like image 55
Sam Mason Avatar answered Nov 02 '25 01:11

Sam Mason