tigo / recommendation
协同过滤推荐系统
v0.0.2
2021-02-23 02:18 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
协同过滤推荐系统
- 基于点赞/点踩或星级评级的排名算法
- 此包可用于任何PHP应用程序或任何框架。
- 下载包:
composer require tigo/recommendation - MIT许可证。 请随意使用此项目。 留下星标⭐或创建分支!
如果您认为此项目有用,请考虑捐赠以支持开发者。
入门指南
从composer开始
- 安装composer
- 下载包:
composer require tigo/recommendation - PHP >= 7.0;已测试的版本:7.2.25,7.3.23和8.0.1。
//Somewhere in your project, you may need to use autoload include __DIR__ ."/vendor/autoload.php";
算法
- 排名
- 欧几里得
- 斜率一
简介
使用协同过滤推荐产品
/** $table gets the array from the database. $user is the foreign key that represents the user who will receive the recommendation. **/ use Tigo\Recommendation\Recommend; // import class $client = new Recommend(); $client->ranking($table,$user); //optional third parameter refers to the score not accepted $client->euclidean($table,$user); //optional third parameter refers to the minimum accepted score $client->slopeOne($table, $user); //optional third parameter refers to the minimum accepted score
配置
有时,可能需要重命名常量的值(根据您的数据库表)。
- 配置:标准键(目录:
./src/configuration/StandardKey.php)
const SCORE = 'score'; //score const PRODUCT_ID = 'product_id'; //Foreign key const USER_ID = 'user_id'; //Foreign key
示例
算法的一个简单的教学演示
/** Example using "rating: liked and disliked" like: score = 1; dislike: score = 0 **/ $table = [ ['product_id'=> 'A', 'score'=> 1, 'user_id'=> 'Pedro' ], ['product_id'=> 'B', 'score'=> 1, 'user_id'=> 'Pedro' ], ['product_id'=> 'A', 'score'=> 1, 'user_id'=> 'João' ], ['product_id'=> 'B', 'score'=> 1, 'user_id'=> 'João' ], ['product_id'=> 'C', 'score'=> 1, 'user_id'=> 'João' ] ]; use Tigo\Recommendation\Recommend; // import class $client = new Recommend(); print_r($client->ranking($table,"Pedro")); // result = ['C' => 2] print_r($client->ranking($table,"Pedro",1)); // result = []; print_r($client->euclidean($table,"Pedro")); // result = ['C' => 1] print_r($client->euclidean($table,"Pedro", 2)); // result = [] ; print_r($client->slopeOne($table,'Pedro')); // result = ['C' => 1] print_r($client->slopeOne($table,'Pedro', 2)); // result = []
支持此项目
如果您有兴趣支持此项目,您可以通过多种方式帮助。留下星标⭐或捐赠任何金额。
资助支持此项目
- []
贡献者
许可证
MIT许可证。请参阅存档 许可证

