【问题标题】:Wilson Confidence Interval for 5 stars rating system using goproblems.com使用 goproblems.com 的 5 星评级系统的威尔逊置信区间
【发布时间】:2015-05-20 18:37:14
【问题描述】:

通过了解 goproblem (http://www.goproblems.com/test/wilson/wilson.php?v1=0&v2=2&v3=0&v4=0&v5=0) 上的示例,我遇到了一些问题。

我已经从上面的示例中编写了自己的代码(尽管它会如何工作):

$stars = 4;
$n = 2;
$xbar = (($stars / $n)-1)/4;
$z = 0;
$Wilson = ((1 + 4 * (($xbar + pow($z,$n) / pow(2,$n) - $z) * sqrt($xbar * (1 - $xbar) / $n + pow($z,2) / 4 * pow($n,2))) / (1 + pow($z, 2) / $n)) - 0.374474917663);
echo $Wilson;

现在我的问题是我没有得到相同的下限分数..我认为我的计算方式有问题,但我不知道是什么..

这是一个例子:上面的 goproblem 链接打开了一个关于下限分数的结果:1.1067061310626。现在尝试镜像(在上面的代码中)我有结果:0.9317113001849..

某事告诉我我完全误解了某事。希望你们能从这里帮助我..

【问题讨论】:

    标签: php rating-system


    【解决方案1】:

    Mark Ba​​dolato 写的一个类可以满足你的需要,你可以使用这个库或者从他的实现中学习。

    class WilsonConfidenceIntervalCalculator {
        const CONFIDENCE = 1.959964;
    
        public function getScore($positiveVotes, $totalVotes) {
            return $totalVotes ? $this->lowerBound($positiveVotes, $totalVotes) : 0;
        }
    
        private function lowerBound($positiveVotes, $totalVotes) {
            $phat           = 1.0 * $positiveVotes / $totalVotes;
            $numerator      = $this->calculationNumerator($totalVotes, self::CONFIDENCE, $phat);
            $denominator    = $this->calculationDenominator($totalVotes, self::CONFIDENCE);
    
            return $numerator / $denominator;
        }
    
        private function calculationDenominator($total, $z) {
            return 1 + $z * $z / $total;
        }
    
        private function calculationNumerator($total, $z, $phat) {
            return $phat + $z * $z / (2 * $total) - $z * sqrt(($phat * (1 - $phat) + $z * $z / (4 * $total)) / $total);
        }
    }
    

    您可以在此处阅读更多相关信息,并了解如何运行单元测试。 https://gist.github.com/mbadolato/8253004

    【讨论】:

    • 谢谢!试过了,效果很好,除了结果不能超过 1,我可以得到 0.9999 的壁橱。我希望它(如示例)上升到 5(获得 5 星评级系统),任何建议?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 2011-04-26
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多