CountVectorizer的参数stop_words可以填写以下内容:

  1. 英文停用词列表:可以使用scikit-learn库自带的停用词列表,例如:"english"。

  2. 自定义停用词列表:可以填写一个自定义的停用词列表,例如:['and', 'the', 'to', 'in', 'of']。

  3. None:不使用停用词列表,保留所有词汇。

  4. callable:可以自定义一个函数,用于过滤停用词。该函数接收一个字符串参数,返回一个布尔值。如果返回True,则该字符串会被过滤掉,否则会保留。

例如,定义一个自定义函数过滤长度小于3的词汇:

def my_stop_words(word):
    return len(word) < 3

然后将该函数作为stop_words参数的值传入CountVectorizer中即可:

vectorizer = CountVectorizer(stop_words=my_stop_words)
CountVectorizer的参数stop_words还可以填写啥

原文地址: https://www.cveoy.top/t/topic/bvPe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录