3

I am looking forward to apply the bayesian approach to prioritize a list that could take the number of likes, dislikes and review counts into consideration.

The approach listed in here relies on the bayesian average:

$bayesian_rating = ( ($avg_num_votes * $avg_rating) + ($this_num_votes * $this_rating) ) / ($avg_num_votes + $this_num_votes);

In my case, there are no $avg_rating since its not a 5-star system, it will never exist, the number of likes, dislikes and reviews always increments therefore i need to take care of the true representation of the listing.

The solution in here was not enough to decide on an approach.

What would the best solution be in case i want to apply a mathematical approach?

Edit added: Ref. @Ina , it is possible to reflect the 5-star system if i multiply the likes by 5 which makes it with the highest value in a 5-star system.

Getting back to the code, after adding some extra variables to take care of (likes, dislikes, number of reviews, number of times added to basket) , i am not sure the what can i fill the $avg_rating and $this_rating with?

Here is the code so far:

// these values extracted from the database
    $total_all_likes = 10; //total likes of all the products
    $total_all_dislikes = 5; //total dislikes of all the products
    $total_all_reviews = 7; //total reviews of all the products
    $total_all_addedToBasket = 2; //total of products that has been added to basket for all the users
    $total_all_votes = ($total_all_likes *5) + $total_all_dislikes;  //total of likes and dislikes
    $total_all_weight = $total_all_votes + $total_all_reviews + $total_all_addedToBasket; //total interactions on all the products
    $total_all_products = 200; //total products count

    //Get the average
    $avg_like = ($total_all_likes*5)/$total_all_votes; //Average of likes of all the votes 
    $avg_dislike = $total_all_dislikes/$total_all_votes; //Average of dislikes of all the votes 
    $avg_reviews = $total_all_reviews/$total_all_products; //Average of reviews of all the products
    $avg_addedToBasket = $total_all_addedToBasket/$total_all_products; //Average of added to basket count of all the products
    $avg_weight = $avg_like + $avg_dislike + $avg_reviews + $avg_addedToBasket; //Total average weight

    //New product, it has not been liked, disliked, added to basket or reviewed 
    $this_like = 0 *5;
    $this_dislike = 0;
    $this_votes  = $this_like + $this_dislike;
    $this_review     = 0;
    $this_addedToBasket = 0;
    $this_weight = $this_votes + $this_review + $this_addedToBasket;

    //$avg_rating
    //$this_rating

    $bayesian_rating = (($avg_weight * $avg_rating) + ($this_weight * $this_rating) ) / ($avg_weight + $this_weight);   
Community
  • 1
  • 1
ebil
  • 33
  • 4

1 Answers1

2

Instead of a 5-star system, you have a binary system. People either 'like' or 'dislike'. The ratings are therefore naturally a number between 0 and 1 calculated by:

likes / (likes + dislikes)

You do not need to multiply by 5 to imitate a 5* rating system.

Your code then becomes:

$avg_rating = $total_all_likes / ($total_all_likes + $total_all_dislikes)
$this_rating = $this_like / ($this_like + $this$total_num_positive_votes / $total_num_votes) // Check you're not dividing by 0
$bayesian_rating = (($avg_num_votes * $avg_rating) + ($this_num_votes * $this_rating) ) / ($avg_num_votes + $this_num_votes);

If you want to also take into account the number of 'baskets' and 'reviews' you can simply treat them as more 'weight'

$this_weight = $this_addedToBasket + $this_votes + $this_review;
$avg_votes = $total_all_votes / $total_all_products;
$avg_weight = $avg_addedToBasket + $avg_votews + $avg_reviews;
$bayesian_rating = (($avg_weight * $avg_rating) + ($this_weight * $this_rating) ) / ($avg_weight + $this_weight);    

This will give you a good relative ranking, however if you wish to see meaningful scores between 0 and 1, then you can normalise by dividing away the weight added by baskets and reviews.

Ina
  • 4,400
  • 6
  • 30
  • 44
  • Do you mean `$total_num_positive_votes = total likes / (total likes + total dislikes)` ? And what about the other criteria's such as number of reviews? Where could that fit in the $bayesian_rating ? – ebil Feb 15 '12 at 21:50
  • No: total_num_positive_votes is simply total likes. total_num_votes is total likes + total dislikes The Bayesian Rating doesn't take into account the number of reviews given. I'm not sure how it could be added, could you perhaps describe your problem in a bit more detail? As I understand it right now, you have a list of products, and each product has a number of votes (positive or negative) and a number of reviews (neutral). – Ina Feb 15 '12 at 22:18
  • Thank you for your fast reply. In fact, this list of products can be added to basket, liked, dislike and reviewed. What i was searching for is an algorithm that will take into consideration **all** these counts of these variables and add them up into the `$bayesia_rating` to obtain a certain _weight_ that will help to sort the list in a 'meaningful' way as the Bayesian approach does in a 5 start system. – ebil Feb 15 '12 at 22:37
  • I have updated my question accordingly, i am not sure of the `$avg_rating` and `$this_rating` values and would the code that i have posted normalize the weight as you included in your answer? Appreciate the help. – ebil Feb 16 '12 at 00:19
  • I've clarified the variables leading up to the final answer for you. – Ina Feb 16 '12 at 14:00