【问题标题】:Adding words to scikit-learn's CountVectorizer's stop list将单词添加到 scikit-learn CountVectorizer 停止列表
【发布时间】:2014-08-14 16:58:22
【问题描述】:

Scikit-learn 的 CountVectorizer 类允许您将字符串“english”传递给参数 stop_words。我想在这个预定义列表中添加一些东西。谁能告诉我该怎么做?

【问题讨论】:

  • 你的意思是你想要默认的'english'stop_words 加上你自己的一些额外的?
  • 这篇文章救了你一命。

标签: python scikit-learn stop-words


【解决方案1】:

根据sklearn.feature_extraction.textsource codeENGLISH_STOP_WORDS 的完整列表(实际上是frozenset,来自stop_words)通过__all__ 公开。因此,如果您想使用该列表以及更多项目,您可以执行以下操作:

from sklearn.feature_extraction import text 

stop_words = text.ENGLISH_STOP_WORDS.union(my_additional_stop_words)

(其中my_additional_stop_words 是任何字符串序列)并将结果用作stop_words 参数。 CountVectorizer.__init__ 的这个输入由 _check_stop_list 解析,它将直接传递新的 frozenset

【讨论】:

  • 有趣的是,该集中只有 318 个停用词。也许这些预先提供的停用词需要由使用它的人扩展。
  • 与 CountVectorizer 配合得非常好(stop_words = text.ENGLISH_STOP_WORDS.union(array_example))
猜你喜欢
  • 2020-01-15
  • 2017-08-30
  • 2011-07-27
  • 2019-03-14
  • 2016-10-18
  • 2017-02-25
  • 2020-05-05
  • 2014-07-13
  • 1970-01-01
相关资源
最近更新 更多