ckmeans
v2.1.0
Published
Ckmeans Javascript Implementation - Fast Univariate Clustering
Downloads
12,440
Readme
ckmeans
A javascript implementation of the ckmeans algorithm. It's effectively a 1-dimensional version of kmeans, where a set of values are clustered into discrete groups. The algorithm has an O(kn log(n))
runtime.
There is also a native version of this package if you need faster performance in node environments, see ckmeans-native
For an alternative API used commonly in data visualization applications, check out d3-scale-cluster.
Getting Started
Using npm
Install the npm package
npm install --save ckmeans
Load into your project
// Using ES6 imports
import ckmeans from 'ckmeans';
// Or, using require
var ckmeans = require('ckmeans');
You can also use something like unpkg.com to include it via <script>
tag in the browser.
Example Usage
This function returns the first value in each cluster
var result = ckmeans([1, 2, 4, 5, 12, 43, 52, 123, 234, 1244], 6);
// [1, 12, 43, 123, 234, 1244]
Thanks
Thanks to Haizhou Wang and Mingzhou Song for developing the original Ckmeans 1D clustering algorithm
Contributing
yarn
yarn test # run tests
yarn build # build distributable files
Publishing
- Build distributable file for browser:
yarn build
- Update CHANGELOG.md with changes in next version bump
- Create new npm version:
npm version [major|minor|patch]
- Push to github with new version tag:
git push origin --tags
- Publish to npm:
npm publish