phpjuice/slopeone

PHP implementation of the Weighted Slope One rating-based collaborative filtering scheme.

v2.0.1 2022-02-26 18:07 UTC

This package is auto-updated.

Last update: 2024-12-17 02:38:45 UTC


README

Tests Maintainability Latest Stable Version Total Downloads License

PHP implementation of the Weighted Slope One rating-based collaborative filtering scheme.

Installation

Slopeone Package requires PHP 7.4 or higher.

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

The supported way of installing Slopeone package is via Composer.

composer require phpjuice/slopeone

Usage

Slopeone Package is designed to be very simple and straightforward to use. All you have to do is to load rating data, then predict future ratings based on the training set provided.

Loading files

The Slopeone object is created by direct instantiation:

use PHPJuice\Slopeone\Algorithm;

// Create an instance
$slopeone = new Algorithm();

Adding Rating values

Adding Rating values can be easily done by providing an array of users ratings via the update() method:

$data =[
  [
    "squid" => 1,
    "cuttlefish" => 0.5,
    "octopus" => 0.2
  ],
  [
    "squid" => 1,
    "octopus" => 0.5,
    "nautilus" => 0.2
  ],
  [
    "squid" => 0.2,
    "octopus" => 1,
    "cuttlefish" => 0.4,
    "nautilus" => 0.4
  ],
  [
    "cuttlefish" => 0.9,
    "octopus" => 0.4,
    "nautilus" => 0.5
  ]
];

$slopeone->update($data);

Predicting ratings

all you have to do to predict ratings for a new user is to run the slopeone::predict method

$results = $slopeone->predict([
    "squid" => 0.4
]);

this should produce the following results

[
  "cuttlefish"=>0.25,
  "octopus"=>0.23333333333333,
  "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 Maintainability Latest Stable Version Total Downloads License