【发布时间】:2013-05-16 22:39:09
【问题描述】:
我正在使用该问题 (Similarity between two text documents) 中获得最多投票的答案中给出的代码来计算文档之间的 TF-IDF。但是,我观察到,当我运行代码而不指定自定义值 min_df(代码中为 1)时,如果两个文档完全不同(因此其中没有共同词),而不是接收TF-IDF 值为 0,我得到以下错误:
ValueError: empty vocabulary; training set may have contained only stop words or min_df (resp. max_df) may be too high (resp. too low).
谁能告诉我怎样才能摆脱这个错误?
【问题讨论】:
-
我认为不是“TF-IDF 值为 0”,而是“余弦相似度为 0”。 TF-IDF 值是大小为
n_features == len(vectorizer.vocabulary_)的向量,对中的每个文档一个向量。
标签: python scipy scikit-learn tf-idf