我可以从 CountVectorizer 手动添加和删除功能吗?

Can I add and remove features manually from CountVectorizer?

我正在做文本分类,并将朴素贝叶斯与 CountVectorizer 结合使用。我正在寻找手动添加和删除功能的方法。也许我可以通过 stop_words 删除功能(这是最好的方法吗?)但我找不到添加功能的方法。如果我使用 'vocabulary' 参数,那么除了词汇表中存在的特征外,不会从文本中提取任何特征。这是个问题

是的,使用 stop_words 删除特征是保持结果一致的最佳方法。您也可以进行遍历并手动删除数据,但这与使用 stop_words 删除它们相同。要向 sklearn 中的 stop_word 添加元素,请执行此操作。

from sklearn.feature_extraction import text 
stop_words = text.ENGLISH_STOP_WORDS.union(additional_stop_words)