We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
corpus=["I'd like an apple.","An apple a day keeps the doctor away.","Never compare an apple to an orange.","I prefer scikit-learn to orange.",]fromsklearn.feature_extraction.textimportTfidfVectorizerimportnumpyasnpvectorizer=TfidfVectorizer()sparse=vectorizer.fit_transform(corpus)# Dot product similiarities, the sentences are short!x=sparse*sparse.T# Skip the first document to itself and add two since documents are 1-indexed, answer: 3 (0.39ish)print("{0}".format(np.argmax(x[0,1:].toarray())+2))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Similarity Scores
You are viewing a single comment's thread. Return to all comments →