Package Exports
- w-cluster
- w-cluster/dist/w-cluster.umd.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (w-cluster) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
w-cluster
A tool for data PCA(Principle Component Analysis) and cluster(K-Means & K-Medoids).
Documentation
To view documentation or get support, visit docs.
Installation
Using npm(ES6 module):
Note: w-cluster is mainly dependent on
ml-pca
,ml-kmeans
andk-medoids
.
npm i w-cluster
Example for PCA(Principle Component Analysis):
Link: [dev source code]
async function testPCA() {
let mat = [
[40, 50, 60],
[50, 70, 60],
[80, 70, 90],
[50, 60, 80]
]
console.log('mat', mat)
// => mat [ [ 40, 50, 60 ], [ 50, 70, 60 ], [ 80, 70, 90 ], [ 50, 60, 80 ] ]
let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })
console.log(resMat)
// => [
// [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],
// [ 50.520478881706346, 69.86935352609807, 59.679283942385844 ],
// [ 77.39502404588043, 70.65388036857387, 91.60517102143689 ],
// [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]
// ]
}
testPCA()
.catch((err) => {
console.log(err)
})
Example for cluster:
Link: [dev source code]
async function testCluster() {
let mode = 'k-medoids'
let mat = [
[40, 50, 60],
[50, 70, 60],
[80, 70, 90],
[50, 60, 80]
]
console.log('mat', mat)
// => mat [ [ 40, 50, 60 ], [ 50, 70, 60 ], [ 80, 70, 90 ], [ 50, 60, 80 ] ]
let resMat = await WCluster.cluster(mat, { mode, kNumber: 2, nCompNIPALS: 2 })
console.log(JSON.stringify(resMat, null, 2))
// => {
// "keys": null,
// "ginds": [
// [ 2 ],
// [ 0, 1, 3 ]
// ],
// "gltdt": [
// [
// [ 80, 70, 90 ]
// ],
// [
// [ 40, 50, 60 ],
// [ 50, 70, 60 ],
// [ 50, 60, 80 ],
// ]
// ],
// "dmat": [
// [
// [77.39502404588043, 70.65388036857387, 91.60517102143689]
// ],
// [
// [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],
// [ 50.520478881706346, 69.86935352609807, 59.679283942385844],
// [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]
// ]
// ]
// }
let ltdt = [
{ name: 'Cameron', a: 40, b: 50, c: 60 },
{ name: 'Buckley', a: 50, b: 70, c: 60 },
{ name: 'Paul', a: 80, b: 70, c: 90 },
{ name: 'Fawcett', a: 50, b: 60, c: 80 },
]
console.log('ltdt', ltdt)
// => ltdt [
// { name: 'Cameron', a: 40, b: 50, c: 60 },
// { name: 'Buckley', a: 50, b: 70, c: 60 },
// { name: 'Paul', a: 80, b: 70, c: 90 },
// { name: 'Fawcett', a: 50, b: 60, c: 80 }
// ]
let resLtdt = await WCluster.cluster(ltdt, { mode, kNumber: 2, nCompNIPALS: 2 })
console.log(JSON.stringify(resLtdt, null, 2))
// => {
// "keys": [ "a", "b", "c" ],
// "ginds": [
// [ 2 ],
// [ 0, 1, 3 ]
// ],
// "gltdt": [
// [
// {
// "name": "Paul", "a": 80, "b": 70, "c": 90
// }
// ],
// [
// {
// "name": "Cameron", "a": 40, "b": 50, "c": 60
// },
// {
// "name": "Buckley", "a": 50, "b": 70, "c": 60
// },
// {
// "name": "Fawcett", "a": 50, "b": 60, "c": 80
// }
// ]
// ],
// "dmat": [
// [
// [77.39502404588043, 70.65388036857387, 91.60517102143689]
// ],
// [
// [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],
// [ 50.520478881706346, 69.86935352609807, 59.679283942385844],
// [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]
// ]
// ]
// }
}
testCluster()
.catch((err) => {
console.log(err)
})
In a browser(UMD module):
Note: w-cluster does not dependent on any package.
[Necessary] Add script for w-cluster.
<!-- for basic -->
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.9/dist/w-cluster.umd.js"></script>
<!-- for web workers -->
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.9/dist/w-cluster.wk.umd.js"></script>
PCA: ex-PCA.html [source code]
cluster for k-means: ex-cluster-k-means.html [source code]
cluster for k-medoids: ex-cluster-k-medoids.html [source code]
cluster for k-medoids with web worker: ex-cluster-webworker-k-medoids.html [source code] * WebWorkers(from blob) does not support IE11.