<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import sklearn.tree
import numpy as np

clf = sklearn.tree.DecisionTreeClassifier()
X = np.array([[1],[10]])
y = np.array(['a','b'])
clf = clf.fit(X,y)

X2 = np.array([[1]])
clf.predict(X2)"><pre class="notranslate"><code class="notranslate">import sklearn.tree
import numpy as np

clf = sklearn.tree.DecisionTreeClassifier()
X = np.array([[1],[10]])
y = np.array(['a','b'])
clf = clf.fit(X,y)

X2 = np.array([[1]])
clf.predict(X2)
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [8]: clf.predict(X2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-8-74a67b90d96d&gt; in &lt;module&gt;()
----&gt; 1 clf.predict(X2)

/Library/Python/2.7/site-packages/sklearn/tree/tree.pyc in predict(self, X)
    336                 predictions[:, k] = self.classes_[k].take(np.argmax(P[:, k],
    337                                                                     axis=1),
--&gt; 338                                                           axis=0)
    339         else:
    340             predictions = P[:, :, 0]

ValueError: could not convert string to float: a"><pre class="notranslate"><code class="notranslate">In [8]: clf.predict(X2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-8-74a67b90d96d&gt; in &lt;module&gt;()
----&gt; 1 clf.predict(X2)

/Library/Python/2.7/site-packages/sklearn/tree/tree.pyc in predict(self, X)
    336                 predictions[:, k] = self.classes_[k].take(np.argmax(P[:, k],
    337                                                                     axis=1),
--&gt; 338                                                           axis=0)
    339         else:
    340             predictions = P[:, :, 0]

ValueError: could not convert string to float: a
</code></pre></div>
<p dir="auto">Interestingly, <code class="notranslate">predict_proba</code> works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [23]: clf.predict_proba(X2)
Out[23]: array([[ 1.,  0.]])"><pre class="notranslate"><code class="notranslate">In [23]: clf.predict_proba(X2)
Out[23]: array([[ 1.,  0.]])
</code></pre></div>
<p dir="auto">Update:<br>
I think most people agree now. The estimators should call <code class="notranslate">unique</code> from the utilities (which is a backport of <code class="notranslate">numpy.unique</code>) and save the results in a <code class="notranslate">classes_</code> attribute.<br>
You can look at QDA and LDA for the pattern.</p>
<p dir="auto">To find classes that not yet support this, use the <code class="notranslate">test_common.py</code>.<br>
Just comment out <a href="https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/tests/test_common.py#L385">this line</a> in <code class="notranslate">test_classifiers_classes</code>.</p>
<p dir="auto">Once that works, we can use the text of the classes as labels and see where it breaks next ;)<br>
If anyone decides to work on this, have a look at my branch <a href="https://github.com/amueller/scikit-learn/tree/arbitrary_labels">here</a> where I started work.</p>