Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
articles = data["Article"].tolist()
uni_tfidf = text.TfidfVectorizer(input=articles, stop_words="english")
uni_matrix = uni_tfidf.fit_transform(articles)
uni_sim = cosine_similarity(uni_matrix)
def recommend_articles(x):
return ", ".join(data["Title"].loc[x.argsort()[-5:-1]])
data["Recommended Articles"] = [recommend_articles(x) for x in uni_sim]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment