Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 13, 2021 14:43
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/45494421bed986fa3f88d63c1f21e17e to your computer and use it in GitHub Desktop.
Save amankharwal/45494421bed986fa3f88d63c1f21e17e to your computer and use it in GitHub Desktop.
def recommend_hotel(location, description):
description = description.lower()
word_tokenize(description)
stop_words = stopwords.words('english')
lemm = WordNetLemmatizer()
filtered = {word for word in description if not word in stop_words}
filtered_set = set()
for fs in filtered:
filtered_set.add(lemm.lemmatize(fs))
country = data[data['countries']==location.lower()]
country = country.set_index(np.arange(country.shape[0]))
list1 = []; list2 = []; cos = [];
for i in range(country.shape[0]):
temp_token = word_tokenize(country["Tags"][i])
temp_set = [word for word in temp_token if not word in stop_words]
temp2_set = set()
for s in temp_set:
temp2_set.add(lemm.lemmatize(s))
vector = temp2_set.intersection(filtered_set)
cos.append(len(vector))
country['similarity']=cos
country = country.sort_values(by='similarity', ascending=False)
country.drop_duplicates(subset='Hotel_Name', keep='first', inplace=True)
country.sort_values('Average_Score', ascending=False, inplace=True)
country.reset_index(inplace=True)
return country[["Hotel_Name", "Average_Score", "Hotel_Address"]].head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment