ilicmiljan/weighted-ratings

一个轻量级的PHP库,用于计算基于用户反馈的排序算法的威尔逊下限分数和贝叶斯近似权重。

v1.1.0 2022-10-22 21:59 UTC

This package is auto-updated.

Last update: 2024-09-23 02:37:01 UTC


README

一个轻量级的PHP库,用于计算基于用户反馈的排序算法的威尔逊下限分数贝叶斯近似权重。

安装

加权评分库通过Composer提供。只需将此行添加到您的composer.json文件中

"ilicmiljan/weighted-ratings": "^1.0"

或者您也可以运行

composer require ilicmiljan/weighted-ratings

请注意,vendor文件夹和vendor/autoload.php脚本是由Composer生成的,它们不属于加权评分库。

配置

可用公式

RatingWeightCalculator::FORMULA_WILSON_LOWER_BOUND
RatingWeightCalculator::FORMULA_BAYESIAN_APPROXIMATION

可选配置参数

  • ausmeNegativeRatingisLessThan - 被假定为负分的评分中的星星数量(默认值:3
  • confidence - 公式中使用的统计置信度(默认值:0.95

没有RatingWeightConfig

您可以使用默认的可选配置参数来计算权重,而无需实例化RateLimiterConfig。这可以通过在RatingWeightCalculator实例中设置formula来实现。

使用RatingWeightConfig

您可以使用所有参数创建一个新的RatingWeightConfig实例,并将其传递给RatingWeightCalculator

更改公式

RatingWeightCalculator的一个实例的公式只能设置一次。在运行时更改公式将抛出异常。

使用方法

使用默认配置参数

$weightCalculator = new RatingWeightCalculator();

$ratingWeight = $weightCalculator->formula(RatingWeightCalculator::FORMULA_WILSON_LOWER_BOUND)
    ->calculateWeight([2,4,6,12,24]);

使用自定义参数

$weightCalculator = new RatingWeightCalculator(
    new RatingWeightConfig(RatingWeightCalculator::FORMULA_WILSON_LOWER_BOUND, 5, 0.9)
);

$ratingWeight = $weightCalculator->calculateWeight([2,4,6,12,24,48,92,184,]);

测试

要在此库中运行单元测试,可以使用此命令

./vendor/bin/phpunit

Infection PHP度量

  • 突变分数指标(MSI):98%
  • 突变代码覆盖率:100%
  • 覆盖代码MSI:98%