擅长:python、mysql、java
<p>您可以使用下面链接中的示例中的“ItemSelector”,为数据中的每一列使用不同的处理方法,然后使用sklearn的FeatureUnion将所有内容组合起来。</p>
<p>我想你的意思是你想把价格当作分类数据来处理?我会说,将数字转换为字符串,然后使用CountVectorizer,并将二进制标志设置为True。</p>
<p>这是一个非常有用的例子:
<a href="http://scikit-learn.org/stable/auto_examples/hetero_feature_union.html#sphx-glr-auto-examples-hetero-feature-union-py" rel="nofollow noreferrer">http://scikit-learn.org/stable/auto_examples/hetero_feature_union.html#sphx-glr-auto-examples-hetero-feature-union-py</a></p>
<p>编辑:另外,count向量器会去掉句点,所以最好不用像这样的标记器来调用它。可能有一个更优雅的解决方案在更少的行,但这也行得通。</p>
<pre><code>def no_tokenizer(t):
return [t]
CountVectorizer(binary=False, tokenizer=no_tokenizer)
</code></pre>
<p>编辑:下面是一个使用ItemSelector的管道示例。我有一个pandas数据帧集,我通过传递一个关键字来传递是否要返回文本、数字数据。</p>
^{pr2}$