Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. def new_review_rating(df, df_review, productID, reviewID, ws, wsp, wgp):
  2. """ Computes a new rating of a review, with a component depending on the sentiment
  3. """
  4. r_mean_ratings = np.mean(df_review.loc[reviewID,:]['Review Rating'])
  5. r_rating = df.loc[productID,reviewID]['Review Rating']
  6. r_sentiment = df.loc[productID,reviewID]['Review Sentiment']
  7. mean_sentiment = np.mean(df.loc[productID,:]['Review Sentiment'])
  8. result = ws*(wsp*r_sentiment + (1-wsp)*mean_sentiment) + (1-ws)*(wgp*r_rating + (1-wgp)*r_mean_ratings)
  9. return result
  10.  
  11. def expertise(df_review, reviewerID, productCategory):
  12. """ Compute the expertise grade of a reviewer in the category of product 'productCategory'
  13. """
  14. reviewer_nb_reviews_in_category = m_get_category(df_review.loc[reviewerID,:])[productCategory]
  15.  
  16. return np.round(1 + 3*np.log(reviewer_nb_reviews_in_category))
  17.  
  18. def new_Product_Rating(df, df_review, productID, we, ws, wsp, wgp):
  19. """ Return the new rating of a product
  20. """
  21. product_Category = df.loc[productID,:]['Categories']
  22. new_ratings = []
  23. r_expertise = []
  24. mean_expertises = []
  25.  
  26. for r in df.loc[productID,:].index:
  27. new_ratings.append(new_review_rating(df, df_review, productID, r, ws, wsp, wgp))
  28.  
  29. r_expertise_for_category = [expertise(df_review, r, category) for category in df.loc[productID,:]['Categories']]
  30. mean_expertises = np.mean(r_expertise_for_category)
  31. r_expertise.append(mean_expertises)
  32.  
  33. result = (1-we)*np.mean(new_ratings) + we*np.average(new_ratings, weights = mean_expertises)
  34. return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement