0

I have a 5 star rating system that outputs a recommendation.

A user inputs a rating based on a Like or Dislike.

What I would like to know is how to convert the number of likes and dislikes into a number which can be put into a 5 star rating system?

An Example:

Say if I have:

172 Likes

101 Dislikes

How would I then get then get the average of these likes and dislikes, to put into a 5 star system which resembles the number of likes compared to dislikes?

4 Answers4

1

One fairly straightforward way is to compute the fraction of likes as

$$ \text{fraction}_\text{likes} = \frac{\text{number}_\text{likes}} {\text{number}_\text{likes}+ \text{number}_\text{dislikes}} $$

and then if $\text{fraction}_\text{likes}$ is below $0.2$, that's one star; if it's at least $0.2$ but less than $0.4$, it's two stars; and so on. More than $0.8$ is five stars.

ETA: If you allow for zero stars, you could break it down as follows: less than $0.1$, zero stars; at least $0.1$ but less than $0.3$, one star; and so on. More than $0.9$ is five stars.

Brian Tung
  • 34,160
  • Okay brilliant, I think this is the best way. This is similar to the answer mentioned above, as you answered first I will mark you as correct. – user3180997 Feb 05 '16 at 18:34
  • That formula helps me a lot. I have structured the range for my project in following manner.

    0 - 0.2 = 1 star

    0.21 - 0.4 = 2 stars

    0..41 - 0.6 = 3 stars

    0.61 - 0.8 = 4 stars

    0.81 - 1.0 = 5 stars

    – Mahbub Alam Khan Dec 29 '20 at 06:12
0

Calculate the percentage of likes. Then have categories for the star amounts. For example

$1$ star : less than $25\%$

$2$ stars : $25\% - 45\%$

$3$ stars : $45\% - 65\%$

$4$ stars : $65\% - 85\%$

$5$ stars : more than $85\%$

ploosu2
  • 8,707
  • This is a option but doesn't take dislikes into consideration so would put a bias on the likes? Say if there were more dislikes then likes this wouldn't be a fair representation? – user3180997 Feb 05 '16 at 18:26
  • @user3180997 Why? The percentage of likes tells exactly how many likes versus dislikes there are. – ploosu2 Feb 05 '16 at 18:29
0

You could do something like: $$\frac{L}{L+D}\cdot 5$$, where $L$ is the number of likes and $D$ is the number of dislikes. This allows for fractions of stars. To get whole stars, just round the numbers either up or down, whichever you want.

Ben Sheller
  • 4,085
  • Okay brilliant thank you, this got me some good numbers - thanks. Someone else answered below so I will mark that as correct, But this works as well. Thank you. I will mark up, – user3180997 Feb 05 '16 at 18:35
0

I was stucked in a simmilar situation and finally came up with a preaty well performing function and have tested for more than 30+ different usecases

You can simply try this

function calculateLikes(starCount,dislikeTotal,likesTotal){
   if(likesTotal==0 || starCount==0) return 0;
  return ((starCount-(dislikeTotal/(likesTotal/starCount))).toFixed(1));
}

Here:

  1. starCount is total no. of Stars
  2. dislikeTotal is total no. of Dislikes
  3. likesTotal is total no. of Likes

And using the function as below

5 star rating system

  console.log(calculateLikes(5,101,172));

Output :- 2.1

10 star rating system

  console.log(calculateLikes(10,101,172));

Output :- 4.1

Atleast that works well as per my expectations.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. – Community Oct 04 '21 at 19:17