python - 将单词添加到 scikit-learn 的 CountVectorizer 的停止列表

标签 python scikit-learn stop-words

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

最佳答案

根据source code对于 sklearn.feature_extraction.textENGLISH_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

关于python - 将单词添加到 scikit-learn 的 CountVectorizer 的停止列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24386489/

相关文章:

python - Django:非员工用户可以登录管理页面

python - url中的当前参数在django中的下一个url中设置

Python - csr_matrix 的数据结构

scikit-learn - 为什么精度和召回率的值几乎与代表性不足的类别的精度和召回率相同

Solr 停用词替换为 _ 符号

python - 比较大列表中的项目 - 查找长度相差 1 个字母的项目 - Python

python - 对列表列表求和以获得求和列表 Python

python - 使用稀疏矩阵与 numpy 数组

java - 当语言被覆盖时搜索停用词无法按预期工作

vectorization - 用户警告 : Your stop_words may be inconsistent with your preprocessing