1 raiting subtraction from total weighted rating - php

This is a 10 star rating.
I have a weighted rating of 8.1 made from 25 users ratings.
I want to delete 1 user rating (7.5) that is invalid, how i do direct calculation on this? I don't want to recalculate all 24 ratings that are left.
I tough of this (8.1+7.5)/2 but it doesn't give me the right answer
Any others ideas of subtraction from a weighted rating?

When you calculate an average, the formula is :
(rate1 + rate2 + ... + rateN) / number of rates.
So, we have this equation where x is the addition of all rates exept the one you want to substract :
(x + 7.5) / 25 = 8.1
x + 7.5 = 8.1 * 25
x = 8.1 * 25 - 7.5
x = 195
So the answer is 195 / 24 = 8.125
Based on previous, the formula is :
(average * total votes - rate to remove) / total votes - 1

Related

A suitable scoring algorithm for 3 scores

I have several objects, each object should be rated by [q]Quality, [v]Value and [s]Suitability by a user.
Currently I am retrieving the total average of each object by Score = (q+v+s/3) - That said I run into the popular issue where an object with 1 rating of 10,10,10 is rated higher than a object with 3 ratings of 10,9,9 | 9,10,10 | 10,10,8 - Not good!
I want to score each object by a total. Is there any algorithm that would be best suited? The end result will be in a PHP environment. An example could be roughly what Awwwards has currently for each of its websites listed.
I've looked around and can see similar requirements and the Bayesian method being suggested, I'm not sure how this would match my requirements though as the need for knowing a 'minimum'?
Digging around a bit more, I've found this - applied to some SQL would this work? Any issues?
<?php
$avg_num_votes = 17; // Average number of reviews on all objects
$avg_rating = 4.5; // Average review for all objects
$this_num_votes = 17; // Number of reviews on this object
$this_rating = 4; // Review for this object
$bayesian_rating = (($avg_num_votes * $avg_rating) + ($this_num_votes * $this_rating)) / ($avg_num_votes + $this_num_votes);
echo $bayesian_rating;
//(FR) = ((av * ar) + (v × r)) / (av + v)
//(FR) = ((17 * 4.5) + (17 * 4)) / (17 + 17)
//(FR) = (76.5 + 68) / 34
//(FR) = 162.5 / 34
//(FR) = 4.25
?>
Laplace smoothing is simple to implement, although you have to choose one parameter. It is what is being called "the Bayesian estimate" or "the Bayesian method" although that is not quite right, and there are many other techniques that more accurately implement Bayesian updating for different choices of prior distributions.
Choose M, called the number of "minimum" ratings by some. Calculate the average rating A over all categories. Give each object M average ratings in addition to the users' ratings. If you change M, this changes how much you trust a small sample. Larger values of M give less credit to small numbers of ratings.
You don't need to adjust this based on having three scores. Call the sum the rating.
For example, suppose the average rating anywhere is 25, you have chosen M=3, and you are comparing one object with 1 rating of 30 to an object with 7 ratings of 27. For the first, you calculate a smoothed rating of (30*1 + 25*3)/(1+3) = 26.25. The smoothed rating of the second is (27*7+25*3)/(7+3) = 26.4. So, the second object would have a slightly higher smoothed rating than the first.

how to calculate top 7 results from 12 rounds

earlier I asked how to get the best 3 results (which OTARIKI and Raging Bull answered)
for a static system that works great.
ok my question.
how can I get the top 7 rounds out of 12 rounds (code below is static best 3 rounds out of 4)
SELECT RacerID , round1 + round2 + round3 + round4 - LEAST(round1, round2, round3, round4) AS Top3Rounds
FROM tablename
any ideas?
many thanks again :)

Convert rating percent (50%) to the equivelant 5-star rating in PHP

I'm sure this is possible but my math isn't that fantastic.
I'm showing latest movies on my page and my application uses a 5-star rating system, however, the data I receive from a Web Service arrives as a percentage e.g. 50%.
Is there any way I can convert this percentage to a star rating equivalent, which in this case would be 50% = 2.5, allowing me to show 2.5 stars?
It seems fairly simple when I have 50% but if I get 94%, it confuses my poor little pea for a brain! Please help.
If you want to convert the 0..100 scale to a 0..5 scale, just divide by 20.
If you want it on a half-star boundary, then divide it by 10 instead and that's the number of half-stars you need.
Keep in mind I'm talking about integer division here, where the value is truncated (rounded down).
You may also want to consider rounding it more intelligently during the division, rather than truncating, so that something like 99% is 5 stars (not 4.5). This can be done by simply adding half the amount you're dividing by before the division, something like (in C):
int percent = 94;
int halfstars = (percent + 5) / 10;
This would give the following results for input values between 0 and 100 inclusive:
percent halfstars
------- ---------
0- 4 0
5- 14 1
15- 24 2
25- 34 3
35- 44 4
45- 54 5
55- 64 6
65- 74 7
75- 84 8
85- 94 9
95-100 10
The formula for finding the percentage of a number is fairly simple:
$percentInDecimalForm * $number
For example, a 94% rating would be:
.94 * 5 = 4.7
You just need to solve the following:
100% ---------- 5
94% ---------- x = (94 * 5) / 100 (=) x = 4.7
Now it's necessary to know the granularity of your star scale (how many times you can divide the star).
Since you mentioned 0.5 stars, I'm gonna assume your star granularity is 1 / 0.5 = 2, so just solve:
round(4.7 * 2) / 2 (=) 9 / 2 (=) 4.5

standard deviation and mode

I have a system that monitors the performance of students. It tabulates the number of students who gained a score of 1,1.25,1.5,....5 (this is our grading system). For example:
grading system number of students
1 12
1.25 10
1.5 15
1.75 15
2 20
2.25 1
2.5 5
2.75 6
3 8
5 0
From this example, I need my system to determine which is the mode and then print it. I also need to get the standard deviation.
I need this in PHP. Can anyone help me with this?
Your ideas, comments, and suggestions are appreciated.
Update:
Here's what I've done so far:
Finished the standard deviation...but there are still discrepancies i can't resolve...when i calculate the standard deviation manually..the answer is different from the output of my system.. >.<
While for the mode I used an array..this is my code:
$sample = array($one[$ctr],$two[$ctr],$three[$ctr],$four[$ctr],$five[$ctr],$six[$ctr],$seven[$ctr],$eight[$ctr],$nine[$ctr],$ten[$ctr],$fda[$ctr]);
rsort($sample);
$holder = $sample[0];
//$holder = $mode;
The sorting is successful and I can the highest number but I need to print the value of $holder to a table using fpdf.
Any ideas, why the value is not visible in the output?
Well, the mode is easy. Just find the grade (2) which has the highest number of students (20) and there you are.
If there's more than one, then it's multi-modal and you should probably allow for that.
For the standard deviation, the method can be found here. It's basically working out the mean of all those numbers (let's simplify this by using 1, 1, 2 and 7):
1 + 1 + 2 + 7 10
------------- = -- = 2.5
4 4
then calculating the square root of the variance of all those samples from that mean:
_____________________________________________
/ (1-2.5)^2 + (1-2.5)^2 + (2-2.5)^2 + (7-2.5)^2
/ ---------------------------------------------
\/ 4
__________________________
/ 2.25 + 2.25 + 0.25 + 20.25
= / --------------------------
\/ 4
= 2.5
If you're asking a beginner-level question like how best to do this in a specific language like PHP, you should investigate the use of arrays and loops.

Simple popularity algorithm (using date submitted and # of votes)

I run a digg-like website that promotes content to the front page when it reaches a certain number of votes. Right now it doesn't take date submitted into consideration.
I'd like to use a simple algorithm that just uses the number of votes and the date submitted to determine whether something should be promoted. I don't want the algorithm to do anything more complex then that (such as iterating over all the vote dates).
EDIT:
Shouldn't the formula be something like this:
30 / (days between post date and now) * (vote count) = weighted vote
Here are some scenarios which seem reasonable for my site, which indicates that the algorithm needs to be more lenient for older items (since older items are less discoverable on the site)
30 / 30 * 30 = 30 (30 days old, promoted with 30 votes)
30 / 5 * 15 = 90 (5 days old, promoted with 15 votes)
30 / 1 * 10 = 300 (1 day old, promoted with 10 votes)
How can the formula be modified so the above 3 give close to the same min weighted vote required for promotion?
You can use the difference between the current date and the submission date to weight the votes.
(threshold - (days between post date and now))/threshold * (vote count) = weighted vote
in code
$weightedVote = ($threshold - $daysOld) / $threshold * $voteCount;
This would have the effect of eliminating posts older than the threshold from consideration. For example, a post 10 days old would have its votes multiplied by 20/30.
Is there a reason why you are assigning an arbitrary number to content when the condition is vote based? I mean - it seems you'd be better off weighing the users and their votes rather than giving a piece of content more or less votes based on the date.
I wrote some pretty mean voting software for a company that had $10,000 + contests and our algorithm considered the user and their history of behavior, which ended up filtering out a lot of spam votes.
This sounds complex but it is not really.
As for your balancing code -
You want 1 day old content to be promoted at 10 votes, where a 30 day item requires 30 votes?
Or do you mean 1 day content with 10 votes is promoted, while a 30 day item with, say, 6 votes could be promoted because it is older and less likely to be seen, so the vote tolerance is reduced?
function daysDifference($endDate, $beginDate)
{
$date_parts1=explode("-", $beginDate);
$date_parts2=explode("-", $endDate);
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date - $start_date;
}
$diff = 30 - daysDifference(date("Y-m-d"), $postdate);
if($diff > 0)
$weight = 30 / $diff + $votes;
else
$weight = $votes;
So, suppose the daysDifference function returned 26 and there were 4 votes originally. This would read 30 / (30 - 26 = 4) = 7.4 + 4 So 11.4 votes total.
For a one day old item with 10 votes, it would read 30 / (30 - 1 = 29) = 1.03 + 10. So 11.03 total.
Roughly the same for this sample, but will vary for others.
The if means that any content over 30 days is just not considered and their votes are equal to actual value.
I could have just misunderstood your needs though.

Categories