【问题标题】:scikit-learn CountVectorizer vocabulary with regexscikit-learn CountVectorizer 词汇表和正则表达式
【发布时间】:2019-03-14 03:33:54
【问题描述】:

拥有这样的语料库:

'This is the first document.',
'This document is the second document.',
'And this is the third one.',
'Is this the first document?'

我正在使用这个词汇[“this”、“document”、“this document”]。 在矢量化器拟合之后,我得到了这些结果:

[[1 1 0]
[1 2 1]
[1 0 0]
[1 1 0]]

这是正确的。 有没有办法我可以使用正则表达式(或其他东西)来在我的语料库的第一行中获取“此文档”功能? 更具体地说,这个 [1 1 1] 比 [1 1 0]?

我的行是这样的:[“这是第一个文档”]。 我可以以某种方式“删除”“是第一个”(或任何词)来获得“此文档”功能吗?也许使用 token_pattern?

【问题讨论】:

  • countVectorizer 应该打印特征的绝对计数。为什么你的价值观是浮动的?你怎么知道这些是正确的?显示代码并解释更多。
  • 对不起,我只是编辑我的问题。

标签: scikit-learn text-analysis countvectorizer


【解决方案1】:

想办法。我真正想做的是根据我的语料库(unigrams 和 bigrams)上的所有单词组合创建特征。 例如,我的行:这是第一个文档。 提取的特征:

this, 
is, 
the, 
first, 
document, 
this is, 
this the, 
this document, 
is the, 
is first, 
is document, 
the first, 
the document, 
first document

我通过编写自己的标记器并在我的 CountVectorizer() 的标记器参数上使用它来做到这一点。

【讨论】:

    猜你喜欢
    • 2020-01-15
    • 2014-10-10
    • 2016-10-18
    • 2018-12-23
    • 2014-08-14
    • 2017-02-25
    • 1970-01-01
    • 2015-03-23
    • 2020-05-05
    相关资源
    最近更新 更多