You are provided with four documents, numbered 1 to 4, each with a single sentence of text. Determine the identifier of the document which is the most similar to the first document, as computed according to the TF-IDF scores.
My name is Ankit,
Ankit name is very famous,
Ankit like his name
India has a lot of beautiful cities
Output the integer (which may be either 2 or 3 or 4), leaving no leading or trailing spaces.
解决方案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)