Bayesian Score - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Bayesian Score.php

  1. <?php
  2.  
  3. $avg_num_reviews = 20.166666666667;
  4. $avg_rating = 4.7162534435262;
  5.  
  6. $provider_1_reviews = 1;
  7. $provider_1_score = 4.3333333333333;
  8.  
  9. $provider_2_reviews = 80;
  10. $provider_2_score = 4.6791666666667;
  11.  
  12. function ba_score($avg_num_votes, $avg_rating, $this_num_votes, $this_rating) {
  13.     $bayesian_rating = 
  14.         ( ($avg_num_votes * $avg_rating) + ($this_num_votes * $this_rating) ) 
  15.         /
  16.         ($avg_num_votes + $this_num_votes)
  17.     ;
  18.     
  19.     return $bayesian_rating;
  20. }
  21.  
  22. echo "Provider 1: " . ba_score($avg_num_reviews, $avg_rating, $provider_1_reviews, $provider_1_score);
  23. echo '<br>';
  24. echo "Provider 2: " . ba_score($avg_num_reviews, $avg_rating, $provider_2_reviews, $provider_2_score);
  25.  
File Description
  • Bayesian Score
  • PHP Code
  • 23 Nov-2020
  • 700 Bytes
You can Share it: