Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def new_review_rating(df, df_review, productID, reviewID, ws, wsp, wgp):
- """ Computes a new rating of a review, with a component depending on the sentiment
- """
- r_mean_ratings = np.mean(df_review.loc[reviewID,:]['Review Rating'])
- r_rating = df.loc[productID,reviewID]['Review Rating']
- r_sentiment = df.loc[productID,reviewID]['Review Sentiment']
- mean_sentiment = np.mean(df.loc[productID,:]['Review Sentiment'])
- result = ws*(wsp*r_sentiment + (1-wsp)*mean_sentiment) + (1-ws)*(wgp*r_rating + (1-wgp)*r_mean_ratings)
- return result
- def expertise(df_review, reviewerID, productCategory):
- """ Compute the expertise grade of a reviewer in the category of product 'productCategory'
- """
- reviewer_nb_reviews_in_category = m_get_category(df_review.loc[reviewerID,:])[productCategory]
- return np.round(1 + 3*np.log(reviewer_nb_reviews_in_category))
- def new_Product_Rating(df, df_review, productID, we, ws, wsp, wgp):
- """ Return the new rating of a product
- """
- product_Category = df.loc[productID,:]['Categories']
- new_ratings = []
- r_expertise = []
- mean_expertises = []
- for r in df.loc[productID,:].index:
- new_ratings.append(new_review_rating(df, df_review, productID, r, ws, wsp, wgp))
- r_expertise_for_category = [expertise(df_review, r, category) for category in df.loc[productID,:]['Categories']]
- mean_expertises = np.mean(r_expertise_for_category)
- r_expertise.append(mean_expertises)
- result = (1-we)*np.mean(new_ratings) + we*np.average(new_ratings, weights = mean_expertises)
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement