Apply Bayesian average in a NON 5-star rating syst

2019-04-11 00:54发布

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);   

1条回答
劫难
2楼-- · 2019-04-11 01:04

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.

查看更多
登录 后发表回答