您将获得四个文档,编号为1到4,每个文档都有一个文本句子。确定与第一个文档最相似的文档标识符,根据TF-IDF分数计算。
My name is Ankit,
Ankit name is very famous,
Ankit like his name
India has a lot of beautiful cities
输出整数(可以是2或3或4),不留前导或尾随空格。
答案 0 :(得分:2)
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
vect = TfidfVectorizer(min_df=1)
tfidf = vect.fit_transform(["My name is Ankit",
"Ankit name is very famous",
"Ankit like his name",
"India has a lot of beautiful cities"])
print ((tfidf * tfidf.T).A)