【问题标题】:How to set sklearn CountVectorizer to include non-alphanumeric characters as the feature extraction?如何设置 sklearn CountVectorizer 以包含非字母数字字符作为特征提取?
【发布时间】:2013-12-06 00:26:01
【问题描述】:

通过使用 NLTK whitespacetokenizer,我可以使用非字母数字术语管理词汇表,但在转换步骤中这些术语不被计算在内,并且它们在所有特征向量中都为 0。因此问题是即使我用简单的空白分区对文档进行了标记,我也需要更改 CountVectorizer 的标记模式。但是,我无法弄清楚我应该使用哪种常规模式?有什么想法吗?

【问题讨论】:

    标签: regex nltk tokenize feature-extraction scikit-learn


    【解决方案1】:

    从你的困惑看来,你需要的是学习RegEx(here)。

    如果您希望令牌匹配所有内容,您可以将CountVectorizer 中的token_pattern 属性设置为:

    .*
    

    意味着它将匹配来自标记器的每个标记。

    如果你只想匹配非字母数字标记,你可以使用:

    [^A-Za-z0-9]*
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-05
      • 2016-10-11
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 2017-09-14
      • 2016-10-29
      • 2017-07-05
      相关资源
      最近更新 更多