|
| 1 | +# OpenCF |
| 2 | + |
| 3 | + |
| 4 | +[](https://github.com/phpjuice/opencf/actions/workflows/cron.yml) |
| 5 | +[](https://packagist.org/packages/phpjuice/opencf) |
| 6 | +[](https://packagist.org/packages/phpjuice/opencf) |
| 7 | +[](https://packagist.org/packages/phpjuice/opencf) |
| 8 | + |
| 9 | +PHP implementation of the (Weighted Slopeone,Cosine, Weighted Cosine) rating-based collaborative filtering schemes. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +OpenCF Package is designed to be very simple and straightforward to use. All you have to do is: |
| 14 | + |
| 15 | +1. Load a training set (dataset) |
| 16 | +3. Predict future ratings using a recommender. (Weighted Slopeone,Cosine, Weighted Cosine) |
| 17 | + |
| 18 | +### Create Recommender Service |
| 19 | + |
| 20 | +The `OpenCF` recommender service is created by direct instantiation: |
| 21 | + |
| 22 | +```php |
| 23 | +use OpenCF\RecommenderService; |
| 24 | + |
| 25 | +// Training Dataset |
| 26 | +$dataset = [ |
| 27 | + "squid" => [ |
| 28 | + "user1" => 1, |
| 29 | + "user2" => 1, |
| 30 | + "user3" => 0.2, |
| 31 | + ], |
| 32 | + "cuttlefish" => [ |
| 33 | + "user1" => 0.5, |
| 34 | + "user3" => 0.4, |
| 35 | + "user4" => 0.9, |
| 36 | + ], |
| 37 | + "octopus" => [ |
| 38 | + "user1" => 0.2, |
| 39 | + "user2" => 0.5, |
| 40 | + "user3" => 1, |
| 41 | + "user4" => 0.4, |
| 42 | + ], |
| 43 | + "nautilus" => [ |
| 44 | + "user2" => 0.2, |
| 45 | + "user3" => 0.4, |
| 46 | + "user4" => 0.5, |
| 47 | + ], |
| 48 | +]; |
| 49 | + |
| 50 | +// Create a recommender service instance |
| 51 | +$recommenderService = new RecommenderService($dataset); |
| 52 | + |
| 53 | +// Retrieve a recommender (Weighted Slopeone) |
| 54 | +$recommender = $recommenderService->weightedSlopeone(); |
| 55 | + |
| 56 | +// Predict future ratings |
| 57 | +$results = $recommender->predict([ |
| 58 | + "squid" => 0.4 |
| 59 | +]); |
| 60 | +``` |
| 61 | + |
| 62 | +This should produce the following results: |
| 63 | + |
| 64 | +```php |
| 65 | +[ |
| 66 | + "cuttlefish" => 0.25, |
| 67 | + "octopus" => 0.23, |
| 68 | + "nautilus" => 0.1 |
| 69 | +]; |
| 70 | +``` |
| 71 | + |
| 72 | + |
| 73 | +[](https://github.com/phpjuice/opencf/actions/workflows/cron.yml) |
| 74 | +[](https://packagist.org/packages/phpjuice/opencf) |
| 75 | +[](https://packagist.org/packages/phpjuice/opencf) |
| 76 | +[](https://packagist.org/packages/phpjuice/opencf) |
0 commit comments