{"id":15685145,"url":"https://github.com/ankane/disco-php","last_synced_at":"2025-11-17T14:23:19.429Z","repository":{"id":54563086,"uuid":"522381527","full_name":"ankane/disco-php","owner":"ankane","description":"Recommendations for PHP using collaborative filtering","archived":false,"fork":false,"pushed_at":"2024-08-09T09:37:49.000Z","size":39,"stargazers_count":17,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T20:51:51.848Z","etag":null,"topics":["recommendation-engine","recommender-system"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-08T02:36:37.000Z","updated_at":"2025-03-04T03:55:19.000Z","dependencies_parsed_at":"2023-01-30T21:00:28.854Z","dependency_job_id":"bdb84b94-b948-46d3-afe7-e05c665786cd","html_url":"https://github.com/ankane/disco-php","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"22be67cd6e4d197956b9f7a5c467c42b23ecc301"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/disco-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/disco-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fdisco-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284895813,"owners_count":27080967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["recommendation-engine","recommender-system"],"created_at":"2024-10-03T17:24:02.372Z","updated_at":"2025-11-17T14:23:19.398Z","avatar_url":"https://github.com/ankane.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Disco PHP\n\n:fire: Recommendations for PHP using collaborative filtering\n\n- Supports user-based and item-based recommendations\n- Works with explicit and implicit feedback\n- Uses high-performance matrix factorization\n\n[![Build Status](https://github.com/ankane/disco-php/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/disco-php/actions)\n\n## Installation\n\nRun:\n\n```sh\ncomposer require ankane/disco\n```\n\nAdd scripts to `composer.json` to download the shared library:\n\n```json\n    \"scripts\": {\n        \"post-install-cmd\": \"Disco\\\\Library::check\",\n        \"post-update-cmd\": \"Disco\\\\Library::check\"\n    }\n```\n\nAnd run:\n\n```sh\ncomposer install\n```\n\n## Getting Started\n\nCreate a recommender\n\n```php\nuse Disco\\Recommender;\n\n$recommender = new Recommender();\n```\n\nIf users rate items directly, this is known as explicit feedback. Fit the recommender with:\n\n```php\n$recommender-\u003efit([\n    ['user_id' =\u003e 1, 'item_id' =\u003e 1, 'rating' =\u003e 5],\n    ['user_id' =\u003e 2, 'item_id' =\u003e 1, 'rating' =\u003e 3]\n]);\n```\n\n\u003e IDs can be integers or strings\n\nIf users don’t rate items directly (for instance, they’re purchasing items or reading posts), this is known as implicit feedback. Leave out the rating.\n\n```php\n$recommender-\u003efit([\n    ['user_id' =\u003e 1, 'item_id' =\u003e 1],\n    ['user_id' =\u003e 2, 'item_id' =\u003e 1]\n]);\n```\n\n\u003e Each `user_id`/`item_id` combination should only appear once\n\nGet user-based recommendations - “users like you also liked”\n\n```php\n$recommender-\u003euserRecs($userId);\n```\n\nGet item-based recommendations - “users who liked this item also liked”\n\n```php\n$recommender-\u003eitemRecs($itemId);\n```\n\nUse the `count` option to specify the number of recommendations (default is 5)\n\n```php\n$recommender-\u003euserRecs($userId, count: 3);\n```\n\nGet predicted ratings for specific users and items\n\n```php\n$recommender-\u003epredict([['user_id' =\u003e 1, 'item_id' =\u003e 2], ['user_id' =\u003e 2, 'item_id' =\u003e 4]]);\n```\n\nGet similar users\n\n```php\n$recommender-\u003esimilarUsers($userId);\n```\n\n## Examples\n\n### MovieLens\n\nLoad the data\n\n```php\nuse Disco\\Data;\n\n$data = Data::loadMovieLens();\n```\n\nCreate a recommender and get similar movies\n\n```php\n$recommender = new Recommender(factors: 20);\n$recommender-\u003efit($data);\n$recommender-\u003eitemRecs('Star Wars (1977)');\n```\n\n## Storing Recommendations\n\nSave recommendations to your database.\n\nAlternatively, you can store only the factors and use a library like [pgvector-php](https://github.com/pgvector/pgvector-php). See an [example](https://github.com/pgvector/pgvector-php/blob/master/examples/disco/example.php).\n\n## Algorithms\n\nDisco uses high-performance matrix factorization.\n\n- For explicit feedback, it uses [stochastic gradient descent](https://www.csie.ntu.edu.tw/~cjlin/papers/libmf/libmf_journal.pdf)\n- For implicit feedback, it uses [coordinate descent](https://www.csie.ntu.edu.tw/~cjlin/papers/one-class-mf/biased-mf-sdm-with-supp.pdf)\n\nSpecify the number of factors and epochs\n\n```php\nnew Recommender(factors: 8, epochs: 20);\n```\n\nIf recommendations look off, trying changing `factors`. The default is 8, but 3 could be good for some applications and 300 good for others.\n\n## Validation\n\nPass a validation set with:\n\n```php\n$recommender-\u003efit($data, validationSet: $validationSet);\n```\n\n## Cold Start\n\nCollaborative filtering suffers from the [cold start problem](https://en.wikipedia.org/wiki/Cold_start_(recommender_systems)). It’s unable to make good recommendations without data on a user or item, which is problematic for new users and items.\n\n```php\n$recommender-\u003euserRecs($newUserId); // returns empty array\n```\n\nThere are a number of ways to deal with this, but here are some common ones:\n\n- For user-based recommendations, show new users the most popular items.\n- For item-based recommendations, make content-based recommendations.\n\n## Reference\n\nGet ids\n\n```php\n$recommender-\u003euserIds();\n$recommender-\u003eitemIds();\n```\n\nGet the global mean\n\n```php\n$recommender-\u003eglobalMean();\n```\n\nGet factors\n\n```php\n$recommender-\u003euserFactors($userId);\n$recommender-\u003eitemFactors($itemId);\n```\n\n## Credits\n\nThanks to [LIBMF](https://github.com/cjlin1/libmf) for providing high performance matrix factorization\n\n## History\n\nView the [changelog](https://github.com/ankane/disco-php/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/disco-php/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/disco-php/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/disco-php.git\ncd disco-php\ncomposer install\ncomposer test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fdisco-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fdisco-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fdisco-php/lists"}