I have used Decision Tree to solve a problem. Then I have used graphviz to obtain the pictorial version of the decision tree.
import graphviz
dot_data = tree.export_graphviz(clf, out_file=None)
graph = graphviz.Source(dot_data)
dot_data = tree.export_graphviz(clf, out_file=None,
feature_names=f_name,
class_names=['Topper', 'Not a topper'],
filled=True, rounded=True,
special_characters=True)
graph = graphviz.Source(dot_data)
graph
I wish to download this tree generated in .png, .jpg, or any suitable format. Is it possible?
From digraph source create an image
digraph source -
graph_data = "digraph G { ...... }"
fie_ext = 'png'
temp_img = 'temp_file'
my_graph = graphviz.Source(graph_data)
my_graph.render(temp_img,format=fie_ext, view=False)
render() method auto generate an image with temp_file.png extension in your current directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With