Created
December 8, 2019 23:24
-
-
Save emrepun/384a6247eec045d6b45c5ad6c68d5641 to your computer and use it in GitHub Desktop.
merged_engine_3.py
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
# Version-4 | |
def get_recommendations_include_rating_count_threshold_positive_negative_reviews(keywords): | |
df = pd.read_csv('city_data_cleared.csv') | |
score_dict = {} | |
for index, row in df.iterrows(): | |
cs_score = CosineSimilarity.cosine_similarity_of(row['description'], keywords) | |
rating = row['rating'] | |
rating_count = row['rating_count'] | |
positive_review_count = row['positive_review'] | |
negative_review_count = row['negative_review'] | |
rating_contribution = RatingExtractor.get_rating_weight_with_count_and_reviews(rating,rating_count,positive_review_count,negative_review_count) | |
final_score = RecommenderEngine.calculate_final_score(cs_score, rating_contribution) | |
score_dict[index] = final_score | |
#sort cities by score and index. | |
sorted_scores = sorted(score_dict.items(), key=operator.itemgetter(1), reverse=True) | |
counter = 0 | |
#create an empty results data frame. | |
resultDF = pd.DataFrame(columns=('city', 'popularity', 'description', 'score')) | |
#get highest scored 5 cities. | |
for i in sorted_scores: | |
#print index and score of the city. | |
#print(i[0], i[1]) | |
resultDF = resultDF.append({'city': df.iloc[i[0]]['city'], 'popularity': df.iloc[i[0]]['popularity'], 'description': df.iloc[i[0]]['description'], 'score': i[1]}, ignore_index=True) | |
counter += 1 | |
if counter>4: | |
break | |
#convert DF to json. | |
json_result = json.dumps(resultDF.to_dict('records')) | |
return json_result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment