Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 10, 2021 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/769bfe19751d52da3002878ceba3c5fa to your computer and use it in GitHub Desktop.
Save amankharwal/769bfe19751d52da3002878ceba3c5fa to your computer and use it in GitHub Desktop.
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]
data.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment