PHPackages                             phpjuice/opencf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpjuice/opencf

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpjuice/opencf
===============

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

v2.2.1(2y ago)975.3k7[2 issues](https://github.com/phpjuice/opencf/issues)MITPHPPHP ^7.4|^8.0|^8.1CI failing

Since Jun 11Pushed 2y ago2 watchersCompare

[ Source](https://github.com/phpjuice/opencf)[ Packagist](https://packagist.org/packages/phpjuice/opencf)[ RSS](/packages/phpjuice-opencf/feed)WikiDiscussions main Synced yesterday

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

OpenCF
======

[](#opencf)

[![tests](https://github.com/phpjuice/opencf/actions/workflows/php.yml/badge.svg?branch=main)](https://github.com/phpjuice/opencf/actions/workflows/php.yml)[![packagist](https://github.com/phpjuice/opencf/actions/workflows/cron.yml/badge.svg?branch=main)](https://github.com/phpjuice/opencf/actions/workflows/cron.yml)[![Maintainability](https://camo.githubusercontent.com/35a004f0a5a6d32ffb7a21956cfc29169b06b05b20553de3ad4330354cdb402e/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f36306231666163353461646464643561346531322f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpjuice/opencf/maintainability)[![Latest Stable Version](https://camo.githubusercontent.com/ec52b3f29771357102c3fb9586ae57dce8a64a303f0bcaabaf0344080c122e25/687474703a2f2f706f7365722e707567782e6f72672f7068706a756963652f6f70656e63662f76)](https://packagist.org/packages/phpjuice/opencf)[![Total Downloads](https://camo.githubusercontent.com/8383ec6f50559ebba0d426db4c33b334a79130b54fed0f4c0331a9518fb4c5c3/687474703a2f2f706f7365722e707567782e6f72672f7068706a756963652f6f70656e63662f646f776e6c6f616473)](https://packagist.org/packages/phpjuice/opencf)[![License](https://camo.githubusercontent.com/f89504eae4fc8139773fb95598cdb7288829b4bc25df99ab28fc26718bd828af/687474703a2f2f706f7365722e707567782e6f72672f7068706a756963652f6f70656e63662f6c6963656e7365)](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
------------

[](#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
-----

[](#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

[](#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-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

[](#getting-predictions)

All you have to do to predict ratings for a new user is to retrieve an engine from the recommender service and &amp; 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
-----------------

[](#running-the-tests)

you can easily run tests using composer

```
composer test
```

Built With
----------

[](#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
---------

[](#changelog)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details and a todo list.

Security
--------

[](#security)

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

Credits
-------

[](#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
----------

[](#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)

license. Please see the [Licence](https://github.com/phpjuice/opencf/blob/main/LICENSE) for more information.

[![tests](https://github.com/phpjuice/opencf/actions/workflows/php.yml/badge.svg?branch=main)](https://github.com/phpjuice/opencf/actions/workflows/php.yml)[![packagist](https://github.com/phpjuice/opencf/actions/workflows/cron.yml/badge.svg?branch=main)](https://github.com/phpjuice/opencf/actions/workflows/cron.yml)[![Maintainability](https://camo.githubusercontent.com/35a004f0a5a6d32ffb7a21956cfc29169b06b05b20553de3ad4330354cdb402e/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f36306231666163353461646464643561346531322f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpjuice/opencf/maintainability)[![Latest Stable Version](https://camo.githubusercontent.com/ec52b3f29771357102c3fb9586ae57dce8a64a303f0bcaabaf0344080c122e25/687474703a2f2f706f7365722e707567782e6f72672f7068706a756963652f6f70656e63662f76)](https://packagist.org/packages/phpjuice/opencf)[![Total Downloads](https://camo.githubusercontent.com/8383ec6f50559ebba0d426db4c33b334a79130b54fed0f4c0331a9518fb4c5c3/687474703a2f2f706f7365722e707567782e6f72672f7068706a756963652f6f70656e63662f646f776e6c6f616473)](https://packagist.org/packages/phpjuice/opencf)[![License](https://camo.githubusercontent.com/f89504eae4fc8139773fb95598cdb7288829b4bc25df99ab28fc26718bd828af/687474703a2f2f706f7365722e707567782e6f72672f7068706a756963652f6f70656e63662f6c6963656e7365)](https://packagist.org/packages/phpjuice/opencf)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~242 days

Recently: every ~302 days

Total

6

Last Release

1001d ago

Major Versions

v1.0.1 → v2.0.02022-02-27

PHP version history (3 changes)v1.0.0PHP &gt;=5.6

v1.0.1PHP &gt;=7.2

v2.0.0PHP ^7.4|^8.0|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/071fef576e19ad7fd90ce1f76ea74521225728cb9fd97c2fc48a1e9a41978f65?d=identicon)[mhdcodes](/maintainers/mhdcodes)

---

Top Contributors

[![mhdcodes](https://avatars.githubusercontent.com/u/9967336?v=4)](https://github.com/mhdcodes "mhdcodes (20 commits)")

---

Tags

collaborative-filteringcollaborative-filtering-algorithmphprecommendation-systemrecommender-systemrecommendationrecommendercollaborative filteringweighted slope onecollaborative filtering engine

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpjuice-opencf/health.svg)

```
[![Health](https://phpackages.com/badges/phpjuice-opencf/health.svg)](https://phpackages.com/packages/phpjuice-opencf)
```

###  Alternatives

[phpjuice/slopeone

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

858.7k](/packages/phpjuice-slopeone)[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.5M28](/packages/rubix-ml)[tigo/recommendation

collaborative filtering recommender systems

869.5k](/packages/tigo-recommendation)[oveleon/contao-recommendation-bundle

Recommendation integration for Contao Open Source CMS

108.2k2](/packages/oveleon-contao-recommendation-bundle)[recolize/module-recommendation-engine-magento2

The Recolize Recommendation Engine Extension for Magento 2

115.6k](/packages/recolize-module-recommendation-engine-magento2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
