{"id":25565993,"url":"https://github.com/bdelespierre/php-kmeans","last_synced_at":"2025-04-06T03:08:00.488Z","repository":{"id":21625481,"uuid":"24945988","full_name":"bdelespierre/php-kmeans","owner":"bdelespierre","description":"PHP K-Means","archived":false,"fork":false,"pushed_at":"2023-02-01T10:03:51.000Z","size":93,"stargazers_count":91,"open_issues_count":11,"forks_count":41,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T02:05:24.847Z","etag":null,"topics":["looking-for-contributors","machine-learning-algorithms","php"],"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/bdelespierre.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-08T15:03:18.000Z","updated_at":"2025-03-03T08:25:35.000Z","dependencies_parsed_at":"2023-02-17T22:00:19.489Z","dependency_job_id":null,"html_url":"https://github.com/bdelespierre/php-kmeans","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdelespierre%2Fphp-kmeans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdelespierre%2Fphp-kmeans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdelespierre%2Fphp-kmeans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdelespierre%2Fphp-kmeans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bdelespierre","download_url":"https://codeload.github.com/bdelespierre/php-kmeans/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"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","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":["looking-for-contributors","machine-learning-algorithms","php"],"created_at":"2025-02-20T22:21:32.891Z","updated_at":"2025-04-06T03:08:00.452Z","avatar_url":"https://github.com/bdelespierre.png","language":"PHP","readme":"# PHP Kmean\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/bdelespierre/php-kmeans.svg?style=flat-square)](https://packagist.org/packages/bdelespierre/php-kmeans)\n[![Build Status](https://img.shields.io/travis/bdelespierre/php-kmeans/master.svg?style=flat-square)](https://travis-ci.org/bdelespierre/php-kmeans)\n[![Quality Score](https://img.shields.io/scrutinizer/g/bdelespierre/php-kmeans.svg?style=flat-square)](https://scrutinizer-ci.com/g/bdelespierre/php-kmeans)\n[![Total Downloads](https://img.shields.io/packagist/dt/bdelespierre/php-kmeans.svg?style=flat-square)](https://packagist.org/packages/bdelespierre/php-kmean)\n\n[K-mean](http://en.wikipedia.org/wiki/K-means_clustering) clustering algorithm implementation in PHP.\n\nPlease also see the [FAQ](#faq)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require bdelespierre/php-kmeans\n```\n\n## Usage\n\n```PHP\nrequire \"vendor/autoload.php\";\n\n// prepare 50 points of 2D space to be clustered\n$points = [\n    [80,55],[86,59],[19,85],[41,47],[57,58],\n    [76,22],[94,60],[13,93],[90,48],[52,54],\n    [62,46],[88,44],[85,24],[63,14],[51,40],\n    [75,31],[86,62],[81,95],[47,22],[43,95],\n    [71,19],[17,65],[69,21],[59,60],[59,12],\n    [15,22],[49,93],[56,35],[18,20],[39,59],\n    [50,15],[81,36],[67,62],[32,15],[75,65],\n    [10,47],[75,18],[13,45],[30,62],[95,79],\n    [64,11],[92,14],[94,49],[39,13],[60,68],\n    [62,10],[74,44],[37,42],[97,60],[47,73],\n];\n\n// create a 2-dimentions space\n$space = new KMeans\\Space(2);\n\n// add points to space\nforeach ($points as $i =\u003e $coordinates) {\n    $space-\u003eaddPoint($coordinates);\n}\n\n// cluster these 50 points in 3 clusters\n$clusters = $space-\u003esolve(3);\n\n// display the cluster centers and attached points\nforeach ($clusters as $num =\u003e $cluster) {\n    $coordinates = $cluster-\u003egetCoordinates();\n    printf(\n        \"Cluster %s [%d,%d]: %d points\\n\",\n        $num,\n        $coordinates[0],\n        $coordinates[1],\n        count($cluster)\n    );\n}\n```\n\n**Note:** the example is given with points of a 2D space but it will work with any dimention \u003e1.\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email benjamin.delespierre@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Benjamin Delespierre](https://github.com/bdelespierre)\n- [Ron Cemer](https://github.com/roncemer)\n- [All Contributors](../../contributors)\n\n## License\n\nLesser General Public License (LGPL). Please see [License File](LICENSE.md) for more information.\n\n## FAQ\n\n### How to get coordinates of a point/cluster:\n```PHP\n$x = $point[0];\n$y = $point[1];\n\n// or\n\nlist($x,$y) = $point-\u003egetCoordinates();\n```\n\n### List all points of a space/cluster:\n\n```PHP\nforeach ($cluster as $point) {\n    printf('[%d,%d]', $point[0], $point[1]);\n}\n```\n\n### Attach data to a point:\n\n```PHP\n$point = $space-\u003eaddPoint([$x, $y, $z], \"user #123\");\n```\n\n### Retrieve point data:\n\n```PHP\n$data = $space[$point]; // e.g. \"user #123\"\n```\n\n### Watch the algorithm run\n\nEach iteration step can be monitored using a callback function passed to `Kmeans\\Space::solve`:\n\n```PHP\n$clusters = $space-\u003esolve(3, function($space, $clusters) {\n    static $iterations = 0;\n\n    printf(\"Iteration: %d\\n\", ++$iterations);\n\n    foreach ($clusters as $i =\u003e $cluster) {\n        printf(\"Cluster %d [%d,%d]: %d points\\n\", $i, $cluster[0], $cluster[1], count($cluster));\n    }\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdelespierre%2Fphp-kmeans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdelespierre%2Fphp-kmeans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdelespierre%2Fphp-kmeans/lists"}