我想使用scikit-learn对两个文本进行分类。但我想自己提取特征。就像使用stop_words='english'
来设置英语停用词列表一样,应用于CountVectorizer。如何设置我自己的词列表,让CountVectorizer进行计数呢?
回答:
您可以将自己的停用词列表提供给CountVectorizer的stop_words参数,这样scikit-learn就不会对您输入的文本中不想计数的词进行计数。例如,如果我不希望“cat”、“dog”和“elephant”这些词作为标记,我会这样实例化CountVectorizer:
CountVectorizer(stop_words=['cat','dog', elephant'])
希望这对您有帮助。