【发布时间】:2018-12-24 01:49:57
【问题描述】:
我正在使用 tfidfvectorizer 对来自许多不同语料库的术语进行评分。
这是我的代码
tfidf = TfidfVectorizer(ngram_range=(1,1), stop_words = 'english', min_df = 0.5)
for corpus in all_corpus:
tfidf.fit_transform(corpus)
每个语料库中的文档数量是多种多样的,所以在构建词汇表时,有些语料库仍然是空的并返回错误:
after pruning, no terms remain. Try a lower min_df or higher max_df
我不想更改最小或最大 DF。我需要的是当没有术语时,跳过转换过程。所以我做了一个像下面这样的条件过滤器
for corpus in all_corpus:
tfidf.fit_transform(corpus)
if tfidf.shape[0] > 0:
\\execute some code here
但是,条件不起作用。有没有办法解决这个问题?
非常感谢所有答案和 cmets。谢谢
【问题讨论】:
标签: python-3.x scikit-learn tfidfvectorizer