<p>这仅仅是因为分类器需要浮点值,而您提供的是字符串。您需要使用<a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html" rel="nofollow noreferrer">LabelEncoder</a>为标签对字符串进行编码,并使用<a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html" rel="nofollow noreferrer">OneHotEncoding</a>、<a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OrdinalEncoder.html#sklearn.preprocessing.OrdinalEncoder" rel="nofollow noreferrer">OrdinalEncoder</a>等对特性进行编码</p>
<p>这里查看这些链接以获取有关使用sklearn编码分类(字符串)值的更多信息</p>
<ul>
<li><a href="https://medium.com/@contactsunny/label-encoder-vs-one-hot-encoder-in-machine-learning-3fc273365621" rel="nofollow noreferrer">Label Encoder vs One Hot Encoding</a></li>
<li><a href="https://towardsdatascience.com/encoding-categorical-features-21a2651a065c" rel="nofollow noreferrer">Encoding Categorical Features</a></li>
<li><a href="https://www.datacamp.com/community/tutorials/categorical-data" rel="nofollow noreferrer">Tutorial on handling categorical data in Python</a></li>
</ul>
<p><strong>更新
阅读Scikit的官方文档,学习对分类值进行编码<a href="https://scikit-learn.org/stable/modules/preprocessing.html#encoding-categorical-features" rel="nofollow noreferrer">at this link</a>。你知道吗</p>