<p dir="auto">Currently plotting a decision tree is a pretty big pain, in particular given how easy it could be in a notebook. jupyter actually has built-in support for showing graphviz graphs.<br>
I suggest we add a function with a lazy graphviz import to return a graphviz graph, instead of writing to a file (it's one call to <code class="notranslate">graphviz.Source()</code>).<br>
Alternatively we could add an option to <code class="notranslate">export_graphviz</code> to return the graph as a string instead of writing to a file. Having to create a StringIO object to show a graph seems silly.</p>
<p dir="auto">Recently I used built-in visualizer for <code class="notranslate">DecisionTreeClassifier</code> in Jupyter and can say that<br>
its interface could be better (example is taken from docs):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; from IPython.display import Image  
&gt;&gt;&gt; dot_data = StringIO()  
&gt;&gt;&gt; tree.export_graphviz(clf, out_file=dot_data,  
                         feature_names=iris.feature_names,  
                         class_names=iris.target_names,  
                         filled=True, rounded=True,  
                         special_characters=True)  
&gt;&gt;&gt; graph = pydot.graph_from_dot_data(dot_data.getvalue())  
&gt;&gt;&gt; Image(graph.create_png())  "><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; from IPython.display import Image  
&gt;&gt;&gt; dot_data = StringIO()  
&gt;&gt;&gt; tree.export_graphviz(clf, out_file=dot_data,  
                         feature_names=iris.feature_names,  
                         class_names=iris.target_names,  
                         filled=True, rounded=True,  
                         special_characters=True)  
&gt;&gt;&gt; graph = pydot.graph_from_dot_data(dot_data.getvalue())  
&gt;&gt;&gt; Image(graph.create_png())  
</code></pre></div>
<p dir="auto">In addition this does not work on Python 3, since at the time of writing <code class="notranslate">pydot</code> cannot be installed for Python 3.<br>
The ideal solution will be something like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sklearn import tree
tc = tree.DecisionTreeClassifier()
...
tree.plot(tc) # or even tc.plot()"><pre class="notranslate"><code class="notranslate">from sklearn import tree
tc = tree.DecisionTreeClassifier()
...
tree.plot(tc) # or even tc.plot()
</code></pre></div>
<p dir="auto">but in this case  <code class="notranslate">tree</code> module should depend on <code class="notranslate">pydot</code> and <code class="notranslate">IPython.display.image</code> modules.<br>
I can fix this issue, but what is the best way to do this?</p>