{"id":13426496,"url":"https://github.com/solzimer/skmeans","last_synced_at":"2025-08-11T05:21:12.014Z","repository":{"id":21617894,"uuid":"93420622","full_name":"solzimer/skmeans","owner":"solzimer","description":"Super fast simple k-means implementation for unidimiensional and multidimensional  data.","archived":false,"fork":false,"pushed_at":"2023-01-03T15:16:18.000Z","size":515,"stargazers_count":76,"open_issues_count":18,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-09T16:20:54.052Z","etag":null,"topics":["browser","centroid","cluster","fast","javascript","k-means","k-means-clustering","kmeans","kmeans-algorithm","kmeans-clustering","multidimensional","nodejs","unidimensional"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solzimer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-05T15:49:35.000Z","updated_at":"2025-05-22T12:00:17.000Z","dependencies_parsed_at":"2023-01-13T21:35:34.647Z","dependency_job_id":null,"html_url":"https://github.com/solzimer/skmeans","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/solzimer/skmeans","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solzimer%2Fskmeans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solzimer%2Fskmeans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solzimer%2Fskmeans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solzimer%2Fskmeans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solzimer","download_url":"https://codeload.github.com/solzimer/skmeans/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solzimer%2Fskmeans/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269799359,"owners_count":24477630,"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-08-10T02:00:08.965Z","response_time":71,"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":["browser","centroid","cluster","fast","javascript","k-means","k-means-clustering","kmeans","kmeans-algorithm","kmeans-clustering","multidimensional","nodejs","unidimensional"],"created_at":"2024-07-31T00:01:36.216Z","updated_at":"2025-08-11T05:21:11.720Z","avatar_url":"https://github.com/solzimer.png","language":"JavaScript","readme":"# skmeans\n\nSuper fast simple k-means and [k-means++](https://en.wikipedia.org/wiki/K-means%2B%2B) implementation for unidimiensional and multidimensional data. Works on nodejs and browser.\n\n## Installation\n```\nnpm install skmeans\n```\n\n## Usage\n### NodeJS\n```javascript\nconst skmeans = require(\"skmeans\");\n\nvar data = [1,12,13,4,25,21,22,3,14,5,11,2,23,24,15];\nvar res = skmeans(data,3);\n```\n\n### Browser\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003cscript src=\"skmeans.js\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\t\u003cscript\u003e\n\t\tvar data = [1,12,13,4,25,21,22,3,14,5,11,2,23,24,15];\n\t\tvar res = skmeans(data,3);\n\n\t\tconsole.log(res);\n\t\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Results\n```javascript\n{\n\tit: 2,\n\tk: 3,\n\tidxs: [ 2, 0, 0, 2, 1, 1, 1, 2, 0, 2, 0, 2, 1, 1, 0 ],\n\tcentroids: [ 13, 23, 3 ]\n}\n```\n\n## API\n### skmeans(data,k,[centroids],[iterations])\nCalculates unidimiensional and multidimensional k-means clustering on *data*. Parameters are:\n* **data** Unidimiensional or multidimensional array of values to be clustered. for unidimiensional data, takes the form of a simple array *[1,2,3.....,n]*. For multidimensional data, takes a\nNxM array *[[1,2],[2,3]....[n,m]]*\n* **k** Number of clusters\n* **centroids** Optional. Initial centroid values. If not provided, the algorith will try to choose an apropiate ones. Alternative values can be:\n  * **\"kmrand\"** Cluster initialization will be random, but with extra checking, so there will no be two equal initial centroids.\n  * **\"kmpp\"** The algorythm will use the [k-means++](https://en.wikipedia.org/wiki/K-means%2B%2B) cluster initialization method.\n* **iterations** Optional. Maximum number of iterations. If not provided, it will be set to 10000.\n* **distance function** Optional. Custom distance function. Takes two points as arguments and returns a scalar number.\n\nThe function will return an object with the following data:\n* **it** The number of iterations performed until the algorithm has converged\n* **k** The cluster size\n* **centroids** The value for each centroid of the cluster\n* **idxs** The index to the centroid corresponding to each value of the data array\n* **test** Function to test new point membership\n\n## Examples\n```javascript\n// k-means with 3 clusters. Random initialization\nvar res = skmeans(data,3);\n\n// k-means with 3 clusters. Initial centroids provided\nvar res = skmeans(data,3,[1,5,9]);\n\n// k-means with 3 clusters. k-means++ cluster initialization\nvar res = skmeans(data,3,\"kmpp\");\n\n// k-means with 3 clusters. Random initialization. 10 max iterations\nvar res = skmeans(data,3,null,10);\n\n// k-means with 3 clusters. Custom distance function\nvar res = skmeans(data,3,null,null,(x1,x2)=\u003eMath.abs(x1-x2));\n\n// Test new point\nvar res = skmeans(data,3,null,10);\nres.test(6);\n\n// Test new point with custom distance\nvar res = skmeans(data,3,null,10);\nres.test(6,(x1,x2)=\u003eMath.abs(x1-x2));\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolzimer%2Fskmeans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolzimer%2Fskmeans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolzimer%2Fskmeans/lists"}