定制 phpjuice/opencf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpjuice/opencf

最新稳定版本:v2.2.1

Composer 安装命令:

composer require phpjuice/opencf

包简介

PHP implementation of the (Weighted Slopeone,Cosine, Weighted Cosine) rating-based collaborative filtering schemes.

README 文档

README

tests packagist Maintainability Latest Stable Version Total Downloads License

PHP implementation of the (Weighted Slopeone,Cosine, Weighted Cosine) rating-based collaborative filtering schemes.

To learn all about it, head over to the extensive documentation.

Installation

OpenCF Package requires PHP 7.4 or higher.

INFO: If you are using an older version of php this package will not function correctly.

The supported way of installing OpenCF package is via Composer.

composer require phpjuice/opencf

Usage

OpenCF Package is designed to be very simple and straightforward to use. All you have to do is:

  1. Load a training set (dataset)
  2. Predict future ratings using a recommender. (Weighted Slopeone,Cosine, Weighted Cosine)

Create Recommender Service

The OpenCF recommender service is created by direct instantiation:

use OpenCF\RecommenderService;

// Create an instance
$recommenderService = new RecommenderService($dataset);

Adding dataset

Adding a dataset to the recommender can be done using the constructor or can be easily done by providing an array of users ratings via the setDataset() method:

$dataset = [
    "squid" => [
        "user1" => 1,
        "user2" => 1,
        "user3" => 0.2,
    ],
    "cuttlefish" => [
        "user1" => 0.5,
        "user3" => 0.4,
        "user4" => 0.9,
    ],
    "octopus" => [
        "user1" => 0.2,
        "user2" => 0.5,
        "user3" => 1,
        "user4" => 0.4,
    ],
    "nautilus" => [
        "user2" => 0.2,
        "user3" => 0.4,
        "user4" => 0.5,
    ],
];

$recommenderService->setDataset($dataset);

Getting Predictions

All you have to do to predict ratings for a new user is to retrieve an engine from the recommender service and & run the predict() method.

// Get a recommender
$recommender = $recommenderService->cosine(); // Cosine recommender
// OR
$recommender = $recommenderService->weightedCosine(); // WeightedCosine recommender
// OR
$recommender = $recommenderService->weightedSlopeone(); // WeightedSlopeone recommender

// Predict future ratings
$results = $recommender->predict([
    "squid" => 0.4
]);

This should produce the following results when using WeightedSlopeone recommender

[
  "cuttlefish" => 0.25,
  "octopus" => 0.23,
  "nautilus" => 0.1
];

Running the tests

you can easily run tests using composer

composer test

Built With

  • PHP - The programing language used
  • Composer - Dependency Management
  • Pest - An elegant PHP Testing Framework

Changelog

Please see the changelog for more information on what has changed recently.

Contributing

Please see CONTRIBUTING.md for details and a todo list.

Security

If you discover any security related issues, please email author instead of using the issue tracker.

Credits

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

license. Please see the Licence for more information.

tests packagist Maintainability Latest Stable Version Total Downloads License

统计信息

  • 总下载量: 4.96k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 97
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 96
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-27