分数 = 伯努利参数的威尔逊分数置信区间的下限

Ane*_*pic 1 sql postgresql statistics

我正在寻找一种基于“观看次数”和“喜欢”进行计算的流行度算法。

似乎答案是使用伯努利参数的威尔逊分数置信区间下限,此处提供算法:http :
//www.evanmiller.org/how-not-to-sort-by-average-rating。 html

该页面上以多种形式提供了该算法 - 数学公式、Ruby 和 SQL。

我需要一个SQL版本,遗憾的是该网站上提供的SQL形式不同于其他两个版本不同,它似乎计算两个积极消极的选票,而Ruby的版本只需要pos赞成票和编号n票的总数。

我正在寻找一个 SQL 语句(Postgres 兼容)来仅根据赞成票进行计算,我会将“观看次数”计为我的n总票数。

(我确实认为我可以positive + negativen在他们的 SQL 中那样对待,但后来我对如何处理感到困惑SQRT((positive * negative) / (positive + negative) + 0.9604)

Gor*_*off 6

“算法”只是取一个比率的置信区间的下限。

如果您只有赞成票,则只需使用赞成票的数量。您引用的目的是平衡赞成票、反对票和总票数。你不需要任何这样的平衡,因为赞成票 = 总票数。

如果你有总票数和赞成票,那么你可以使用:

SELECT widget_id, ((positive + 1.9208) / (positive + negative) - 
                   1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) / 
                          (positive + negative)) / (1 + 3.8416 / (positive + negative)) 
       AS ci_lower_bound
FROM (select w.*, (total - positive) as negative
      from widgets w
     )
WHERE positive + negative > 0 
ORDER BY ci_lower_bound DESC;
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我不确定威尔逊校正给出的结果是否比正分数的一个标准差下限更好:

SELECT widget_id, positive/total - sqrt(positive*negative/total)/total
Run Code Online (Sandbox Code Playgroud)