擅长:python、mysql、java
<p>我遇到了同样的问题,发现您可以使用这个<code>util</code>函数检查目标的类型:</p>
<pre><code>from sklearn.utils.multiclass import type_of_target
type_of_target(y)
'multilabel-indicator'
</code></pre>
<p>从其docstring:</p>
<blockquote>
<ul>
<li>'binary': <code>y</code> contains <= 2 discrete values and is 1d or a column
vector.</li>
<li>'multiclass': <code>y</code> contains more than two discrete values, is not a
sequence of sequences, and is 1d or a column vector.</li>
<li>'multiclass-multioutput': <code>y</code> is a 2d array that contains more
than two discrete values, is not a sequence of sequences, and both
dimensions are of size > 1.</li>
<li>'multilabel-indicator': <code>y</code> is a label indicator matrix, an array
of two dimensions with at least two columns, and at most 2 unique
values.</li>
</ul>
</blockquote>
<p>使用<code>LabelEncoder</code>可以将类转换为一维数字数组(假设目标标签位于一维类别/对象数组中):</p>
<pre><code>from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()
y = label_encoder.fit_transform(target_labels)
</code></pre>