https://github.com/phpjuice/opencf
PHP implementation of the (Weighted Slopeone,Cosine, Weighted Cosine) rating-based collaborative filtering schemes.
https://github.com/phpjuice/opencf
collaborative-filtering collaborative-filtering-algorithm php recommendation-system recommender-system
Last synced: 4 months ago
JSON representation
PHP implementation of the (Weighted Slopeone,Cosine, Weighted Cosine) rating-based collaborative filtering schemes.
- Host: GitHub
- URL: https://github.com/phpjuice/opencf
- Owner: phpjuice
- License: mit
- Created: 2020-06-11T19:38:31.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-10-05T12:39:37.000Z (about 2 years ago)
- Last Synced: 2025-03-24T10:09:45.360Z (7 months ago)
- Topics: collaborative-filtering, collaborative-filtering-algorithm, php, recommendation-system, recommender-system
- Language: PHP
- Homepage: https://phpjuice.gitbook.io/opencf
- Size: 68.4 KB
- Stars: 96
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# OpenCF
[](https://github.com/phpjuice/opencf/actions/workflows/php.yml)
[](https://github.com/phpjuice/opencf/actions/workflows/cron.yml)
[](https://codeclimate.com/github/phpjuice/opencf/maintainability)
[](https://packagist.org/packages/phpjuice/opencf)
[](https://packagist.org/packages/phpjuice/opencf)
[](https://packagist.org/packages/phpjuice/opencf)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](https://phpjuice.gitbook.io/opencf).
## 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.
```bash
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:
```php
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:```php
$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.```php
// 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
```php
[
"cuttlefish" => 0.25,
"octopus" => 0.23,
"nautilus" => 0.1
];
```## Running the tests
you can easily run tests using composer
```bash
composer test
```## Built With
- [PHP](http://www.php.net) - The programing language used
- [Composer](https://getcomposer.org) - Dependency Management
- [Pest](https://pestphp.com) - An elegant PHP Testing Framework## Changelog
Please see the [changelog](changelog.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING.md](./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
- [Daniel Lemire](https://github.com/lemire)
- [SlopeOne Predictors for Online Rating-Based Collaborative Filtering](https://www.researchgate.net/publication/1960789_Slope_One_Predictors_for_Online_Rating-Based_Collaborative_Filtering)
- [Distance Weighted Cosine Similarity](https://link.springer.com/chapter/10.1007/978-3-642-41278-3_74)## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see
the [tags on this repository](https://github.com/PHPJuice/opencf/tags).## License
license. Please see the [Licence](https://github.com/phpjuice/opencf/blob/main/LICENSE) for more information.
[](https://github.com/phpjuice/opencf/actions/workflows/php.yml)
[](https://github.com/phpjuice/opencf/actions/workflows/cron.yml)
[](https://codeclimate.com/github/phpjuice/opencf/maintainability)
[](https://packagist.org/packages/phpjuice/opencf)
[](https://packagist.org/packages/phpjuice/opencf)
[](https://packagist.org/packages/phpjuice/opencf)