Scikit-learn 的 CountVectorizer类允许您将字符串“英语”传递给参数 stop_words。我想在这个预定义列表中添加一些东西。谁能告诉我该怎么做?
最佳答案
根据source code对于 sklearn.feature_extraction.text
,ENGLISH_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/