-1
我试图实现在信息检索论文中描述的一种技术,其中将文档分解为向量,然后计算它们的余弦相似度,就像这里解释的那样:http://blog.christianperone.com/2013/09/machine-learning-cosine-similarity-for-vector-space-models-part-iii/合并两个CountVectorizer并计算余弦相似度
在这个例子中,我们有:
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
documents = (
"The sky is blue",
"The sun is bright",
"The sun in the sky is bright",
"We can see the shining sun, the bright sun"
)
tfidf_vectorizer = TfidfVectorizer()
tfidf_matrix = tfidf_vectorizer.fit_transform(documents)
cosine_similarity(tfidf_matrix[0:1], tfidf_matrix)
然而,时不时我会得到一个新的文档。有没有办法计算这个新文档的余弦相似度,而不重新生成documents
元组和tfidf_matrix
?