-
-
Save amankharwal/160e287957f2bf8e6e3ca3cc305ed9f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recommend(name, cosine_similarities = cosine_similarities): | |
# Create a list to put top restaurants | |
recommend_restaurant = [] | |
# Find the index of the hotel entered | |
idx = indices[indices == name].index[0] | |
# Find the restaurants with a similar cosine-sim value and order them from bigges number | |
score_series = pd.Series(cosine_similarities[idx]).sort_values(ascending=False) | |
# Extract top 30 restaurant indexes with a similar cosine-sim value | |
top30_indexes = list(score_series.iloc[0:31].index) | |
# Names of the top 30 restaurants | |
for each in top30_indexes: | |
recommend_restaurant.append(list(df_percent.index)[each]) | |
# Creating the new data set to show similar restaurants | |
df_new = pd.DataFrame(columns=['cuisines', 'Mean Rating', 'cost']) | |
# Create the top 30 similar restaurants with some of their columns | |
for each in recommend_restaurant: | |
df_new = df_new.append(pd.DataFrame(df_percent[['cuisines','Mean Rating', 'cost']][df_percent.index == each].sample())) | |
# Drop the same named restaurants and sort only the top 10 by the highest rating | |
df_new = df_new.drop_duplicates(subset=['cuisines','Mean Rating', 'cost'], keep=False) | |
df_new = df_new.sort_values(by='Mean Rating', ascending=False).head(10) | |
print('TOP %s RESTAURANTS LIKE %s WITH SIMILAR REVIEWS: ' % (str(len(df_new)), name)) | |
return df_new | |
recommend('Pai Vihar') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment