Number of Likes and Dislikes to Star Rating system

1.9k Views Asked by At

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

There are 4 best solutions below

2
On BEST ANSWER

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.

2
On

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\%$

1
On

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.

1
On

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.