from sklearn.feature_extraction.text import TfidfVectorizer
corpus = [
'This is the first document.',
'This is the second second document.',
'And the third one.',
'Is this the first document?'
]
X = TfidfVectorizer(preprocessor=preProcess)
X.fit(corpus)
X.get_feature_names()
preprocessor : callable or None (default) Override the preprocessing
(string transformation) stage while preserving the tokenizing and
n-grams generation steps.
您只需定义一个函数,它接受一个字符串作为输入并重新运行要预处理的内容。例如,一个简单的大写字符串函数如下所示:
一旦创建了函数,就只需将其传递到
TfidfVectorizer
对象中。例如:结果:
这间接地回答了您的后续问题,因为尽管小写被设置为true,但是大写的预处理函数会覆盖它。文件中也提到了这一点:
相关问题 更多 >
编程相关推荐