<p dir="auto">Code to reproduce -</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import export_graphviz
import numpy as np

dtc = DecisionTreeClassifier().fit(np.random.random_sample((20, 2)), np.zeros((20, 1)))
export_graphviz(dtc, filled=True)"><pre class="notranslate"><code class="notranslate">from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import export_graphviz
import numpy as np

dtc = DecisionTreeClassifier().fit(np.random.random_sample((20, 2)), np.zeros((20, 1)))
export_graphviz(dtc, filled=True)
</code></pre></div>
<p dir="auto">This is because the <code class="notranslate">max_impurity</code> and <code class="notranslate">min_impurity</code> are the same for a single node tree (<code class="notranslate">colors['bounds'][0]</code> == <code class="notranslate">colors['bounds'][1]</code>).</p>
<p dir="auto">We should set the color in this case to a single value directly.</p>
<p dir="auto">Example:<br>
<code class="notranslate">from sklearn import tree</code><br>
<code class="notranslate">clf = tree.DecisionTreeClassifier()</code><br>
<code class="notranslate">clf.fit([[0]],[1])</code><br>
<code class="notranslate">tree.export_graphviz(clf, filled=True)</code></p>
<p dir="auto">We'll get error in line 160 of sklearn/tree/export.py:<br>
<code class="notranslate">alpha = int(np.round(255 * ((value - colors['bounds'][0]) / (colors['bounds'][1] - colors['bounds'][0])), 0))</code></p>
<blockquote>
<p dir="auto">ValueError: cannot convert float NaN to integer</p>
</blockquote>
<p dir="auto">Basically we will get zero division, because <code class="notranslate">colors['bounds'][0]</code> equals <code class="notranslate">colors['bounds'][1]</code>.</p>