w-cluster 1.0.8 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsdoc +1 -1
- package/LICENSE +1 -1
- package/README.md +31 -38
- package/dist/w-cluster.umd.js +2 -2
- package/dist/w-cluster.umd.js.map +1 -1
- package/dist/w-cluster.wk.umd.js +1 -1
- package/docs/WCluster.mjs.html +48 -56
- package/docs/examples/ex-PCA.html +1 -1
- package/docs/examples/{ex-cluster-webworker-k-medoids.html → ex-cluster-webworker.html} +12 -4
- package/docs/examples/{ex-cluster-k-means.html → ex-cluster.html} +11 -3
- package/docs/global.html +11 -6
- package/docs/index.html +1 -1
- package/examples/{ex-cluster-webworker-k-medoids.html → ex-cluster-webworker.html} +11 -3
- package/examples/{ex-cluster-k-means.html → ex-cluster.html} +10 -2
- package/g-cluster-nodeworker.mjs +20 -20
- package/g-cluster.mjs +20 -28
- package/package.json +3 -8
- package/src/WCluster.mjs +47 -55
- package/src/WClusterCore.mjs +14 -9
- package/src/WClusterMat.mjs +4 -3
- package/src/WPCAMat.mjs +7 -5
- package/test/cluster.test.mjs +2 -2
- package/toolg/gDistRollup.mjs +15 -16
- package/docs/examples/ex-cluster-k-medoids.html +0 -138
- package/examples/ex-cluster-k-medoids.html +0 -138
package/src/WCluster.mjs
CHANGED
|
@@ -11,33 +11,6 @@ import WClusterCore from './WClusterCore.mjs'
|
|
|
11
11
|
* @param {Number} [opt.nCompNIPALS=2] 輸入指定降維的維度整數,不能超過數據的維度(各列有效元素數量),預設2
|
|
12
12
|
* @return {Promise} 回傳Promise,resolve回傳指定維數數值的陣列,reject回傳錯誤訊息
|
|
13
13
|
* @example
|
|
14
|
-
*
|
|
15
|
-
* async function testPCA() {
|
|
16
|
-
*
|
|
17
|
-
* let mat = [
|
|
18
|
-
* [40, 50, 60],
|
|
19
|
-
* [50, 70, 60],
|
|
20
|
-
* [80, 70, 90],
|
|
21
|
-
* [50, 60, 80]
|
|
22
|
-
* ]
|
|
23
|
-
* console.log('mat', mat)
|
|
24
|
-
* // => mat [ [ 40, 50, 60 ], [ 50, 70, 60 ], [ 80, 70, 90 ], [ 50, 60, 80 ] ]
|
|
25
|
-
*
|
|
26
|
-
* let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })
|
|
27
|
-
* console.log(resMat)
|
|
28
|
-
* // => [
|
|
29
|
-
* // [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],
|
|
30
|
-
* // [ 50.520478881706346, 69.86935352609807, 59.679283942385844 ],
|
|
31
|
-
* // [ 77.39502404588043, 70.65388036857387, 91.60517102143689 ],
|
|
32
|
-
* // [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]
|
|
33
|
-
* // ]
|
|
34
|
-
*
|
|
35
|
-
* }
|
|
36
|
-
* testPCA()
|
|
37
|
-
* .catch((err) => {
|
|
38
|
-
* console.log(err)
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
14
|
*/
|
|
42
15
|
async function PCA(data, opt = {}) {
|
|
43
16
|
return WPCAMat(data, opt)
|
|
@@ -53,6 +26,7 @@ async function PCA(data, opt = {}) {
|
|
|
53
26
|
* @param {Number} [opt.nCompNIPALS=2] 輸入指定降維的維度整數,不能超過數據的維度(各列有效元素數量),預設2
|
|
54
27
|
* @param {String} [opt.mode='k-medoids'] 輸入分群方法字串,可為'k-means'、'k-medoids',k-means受初始隨機群中心影響較大,預設'k-medoids'
|
|
55
28
|
* @return {Promise} 回傳Promise,resolve回傳分群後結果物件,keys代表分群有使用到的欄位,ginds代表分群後的指標陣列,gltdt代表分群後的物件陣列,gmat代表分群後且經過PCA處理的數據陣列,其內因是降維後的數據,可例如取最左2欄的數據代表x,y來繪製分群後二維分佈圖,reject回傳錯誤訊息
|
|
29
|
+
* @example
|
|
56
30
|
*/
|
|
57
31
|
async function cluster(data, opt = {}) {
|
|
58
32
|
try {
|
|
@@ -70,6 +44,32 @@ async function cluster(data, opt = {}) {
|
|
|
70
44
|
* @return {Object} 回傳物件,其內有PCA與cluster函式,PCA為主成份分析,cluster為分群分析
|
|
71
45
|
* @example
|
|
72
46
|
*
|
|
47
|
+
* async function testPCA() {
|
|
48
|
+
*
|
|
49
|
+
* let mat = [
|
|
50
|
+
* [40, 50, 60],
|
|
51
|
+
* [50, 70, 60],
|
|
52
|
+
* [80, 70, 90],
|
|
53
|
+
* [50, 60, 80]
|
|
54
|
+
* ]
|
|
55
|
+
* console.log('mat', mat)
|
|
56
|
+
* // => mat [ [ 40, 50, 60 ], [ 50, 70, 60 ], [ 80, 70, 90 ], [ 50, 60, 80 ] ]
|
|
57
|
+
*
|
|
58
|
+
* let resMat = await WCluster.PCA(mat, { nCompNIPALS: 2 })
|
|
59
|
+
* console.log(resMat)
|
|
60
|
+
* // => [
|
|
61
|
+
* // [ 36.76572825085965, 50.81184119955175, 61.992939427698765 ],
|
|
62
|
+
* // [ 50.520478881706346, 69.86935352609807, 59.679283942385844 ],
|
|
63
|
+
* // [ 77.39502404588043, 70.65388036857387, 91.60517102143689 ],
|
|
64
|
+
* // [ 55.318768821553576, 58.66492490577632, 76.7226056084785 ]
|
|
65
|
+
* // ]
|
|
66
|
+
*
|
|
67
|
+
* }
|
|
68
|
+
* testPCA()
|
|
69
|
+
* .catch((err) => {
|
|
70
|
+
* console.log(err)
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
73
|
* async function testCluster() {
|
|
74
74
|
* let mode = 'k-medoids'
|
|
75
75
|
*
|
|
@@ -90,24 +90,24 @@ async function cluster(data, opt = {}) {
|
|
|
90
90
|
* // [ 2 ],
|
|
91
91
|
* // [ 0, 1, 3 ]
|
|
92
92
|
* // ],
|
|
93
|
-
* // "
|
|
93
|
+
* // "gmat": [
|
|
94
94
|
* // [
|
|
95
|
-
* // [
|
|
95
|
+
* // [ 77.39502404588043, 70.65388036857387 ]
|
|
96
96
|
* // ],
|
|
97
97
|
* // [
|
|
98
|
-
* // [
|
|
99
|
-
* // [ 50,
|
|
100
|
-
* // [
|
|
98
|
+
* // [ 36.76572825085965, 50.81184119955175 ],
|
|
99
|
+
* // [ 50.520478881706346, 69.86935352609807 ],
|
|
100
|
+
* // [ 55.318768821553576, 58.66492490577632 ]
|
|
101
101
|
* // ]
|
|
102
102
|
* // ],
|
|
103
|
-
* // "
|
|
103
|
+
* // "gltdt": [
|
|
104
104
|
* // [
|
|
105
|
-
* // [
|
|
105
|
+
* // [ 80, 70, 90 ]
|
|
106
106
|
* // ],
|
|
107
107
|
* // [
|
|
108
|
-
* // [
|
|
109
|
-
* // [ 50
|
|
110
|
-
* // [
|
|
108
|
+
* // [ 40, 50, 60 ],
|
|
109
|
+
* // [ 50, 70, 60 ],
|
|
110
|
+
* // [ 50, 60, 80 ]
|
|
111
111
|
* // ]
|
|
112
112
|
* // ]
|
|
113
113
|
* // }
|
|
@@ -134,32 +134,24 @@ async function cluster(data, opt = {}) {
|
|
|
134
134
|
* // [ 2 ],
|
|
135
135
|
* // [ 0, 1, 3 ]
|
|
136
136
|
* // ],
|
|
137
|
-
* // "
|
|
137
|
+
* // "gmat": [
|
|
138
138
|
* // [
|
|
139
|
-
* //
|
|
140
|
-
* // "name": "Paul", "a": 80, "b": 70, "c": 90
|
|
141
|
-
* // }
|
|
139
|
+
* // [ 77.39502404588043, 70.65388036857387 ]
|
|
142
140
|
* // ],
|
|
143
141
|
* // [
|
|
144
|
-
* //
|
|
145
|
-
* //
|
|
146
|
-
* //
|
|
147
|
-
* // {
|
|
148
|
-
* // "name": "Buckley", "a": 50, "b": 70, "c": 60
|
|
149
|
-
* // },
|
|
150
|
-
* // {
|
|
151
|
-
* // "name": "Fawcett", "a": 50, "b": 60, "c": 80
|
|
152
|
-
* // }
|
|
142
|
+
* // [ 36.76572825085965, 50.81184119955175 ],
|
|
143
|
+
* // [ 50.520478881706346, 69.86935352609807 ],
|
|
144
|
+
* // [ 55.318768821553576, 58.66492490577632 ]
|
|
153
145
|
* // ]
|
|
154
146
|
* // ],
|
|
155
|
-
* // "
|
|
147
|
+
* // "gltdt": [
|
|
156
148
|
* // [
|
|
157
|
-
* //
|
|
149
|
+
* // { "name": "Paul", "a": 80, "b": 70, "c": 90 }
|
|
158
150
|
* // ],
|
|
159
151
|
* // [
|
|
160
|
-
* //
|
|
161
|
-
* //
|
|
162
|
-
* //
|
|
152
|
+
* // { "name": "Cameron", "a": 40, "b": 50, "c": 60 },
|
|
153
|
+
* // { "name": "Buckley", "a": 50, "b": 70, "c": 60 },
|
|
154
|
+
* // { "name": "Fawcett", "a": 50, "b": 60, "c": 80 }
|
|
163
155
|
* // ]
|
|
164
156
|
* // ]
|
|
165
157
|
* // }
|
package/src/WClusterCore.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import get from 'lodash/get'
|
|
2
2
|
import each from 'lodash/each'
|
|
3
3
|
import size from 'lodash/size'
|
|
4
|
+
import take from 'lodash/take'
|
|
4
5
|
import map from 'lodash/map'
|
|
5
6
|
import values from 'lodash/values'
|
|
6
7
|
import dtpick from 'wsemi/src/dtpick.mjs'
|
|
@@ -59,18 +60,15 @@ function WClusterCore(data, opt = {}) {
|
|
|
59
60
|
if (!isnum(kNumber)) {
|
|
60
61
|
kNumber = 2
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
kNumber = cint(kNumber)
|
|
64
|
-
}
|
|
63
|
+
kNumber = cint(kNumber)
|
|
65
64
|
|
|
66
65
|
//nCompNIPALS
|
|
67
66
|
let nCompNIPALS = get(opt, 'nCompNIPALS')
|
|
68
67
|
if (!isnum(nCompNIPALS)) {
|
|
69
68
|
nCompNIPALS = 2
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
70
|
+
nCompNIPALS = cint(nCompNIPALS)
|
|
71
|
+
console.log('nCompNIPALS', nCompNIPALS)
|
|
74
72
|
|
|
75
73
|
//mode, 由WDataCluster檢核與給予預設值
|
|
76
74
|
let mode = get(opt, 'mode')
|
|
@@ -117,6 +115,13 @@ function WClusterCore(data, opt = {}) {
|
|
|
117
115
|
//WPCAMat
|
|
118
116
|
let pcad = WPCAMat(mat, { nCompNIPALS })
|
|
119
117
|
|
|
118
|
+
//保留維度
|
|
119
|
+
pcad = map(pcad, (v) => {
|
|
120
|
+
v = take(v, nCompNIPALS)
|
|
121
|
+
return v
|
|
122
|
+
})
|
|
123
|
+
// console.log('pcad', pcad)
|
|
124
|
+
|
|
120
125
|
//WClusterMat
|
|
121
126
|
let ginds = WClusterMat(pcad, { kNumber, mode })
|
|
122
127
|
|
|
@@ -136,9 +141,9 @@ function WClusterCore(data, opt = {}) {
|
|
|
136
141
|
|
|
137
142
|
return {
|
|
138
143
|
keys: ks,
|
|
139
|
-
ginds,
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
ginds, //各群所屬樣本指標
|
|
145
|
+
gmat, //各群所屬主成份分析轉換後樣本數據
|
|
146
|
+
gltdt, //各群所屬原始樣本數據
|
|
142
147
|
}
|
|
143
148
|
}
|
|
144
149
|
|
package/src/WClusterMat.mjs
CHANGED
|
@@ -43,11 +43,12 @@ function kMedoids(data, kNumber) {
|
|
|
43
43
|
|
|
44
44
|
function kMeans(data, kNumber) {
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
//kmeans
|
|
47
47
|
let r = kmeans(data, kNumber)
|
|
48
|
-
//k
|
|
48
|
+
//k: [ 0, 1, 2, 3 ]
|
|
49
49
|
//clusters: [ 0, 0, 1, 0 ]
|
|
50
50
|
|
|
51
|
+
//gs
|
|
51
52
|
let gs = {}
|
|
52
53
|
each(r.clusters, (v, k) => {
|
|
53
54
|
if (!gs[v]) {
|
|
@@ -93,7 +94,7 @@ function WClusterMat(data, opt = {}) {
|
|
|
93
94
|
rs = kMeans(data, kNumber)
|
|
94
95
|
}
|
|
95
96
|
else {
|
|
96
|
-
throw new Error(
|
|
97
|
+
throw new Error(`invalid mode[${mode}]`)
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
return rs
|
package/src/WPCAMat.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
import get from 'lodash/get'
|
|
3
3
|
import size from 'lodash/size'
|
|
4
|
-
import isNumber from 'lodash/isNumber'
|
|
5
|
-
import isBoolean from 'lodash/isBoolean'
|
|
6
4
|
import isearr from 'wsemi/src/isearr.mjs'
|
|
5
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
6
|
+
import isnum from 'wsemi/src/isnum.mjs'
|
|
7
|
+
import cint from 'wsemi/src/cint.mjs'
|
|
7
8
|
import { PCA } from 'ml-pca'
|
|
8
9
|
|
|
9
10
|
|
|
@@ -16,15 +17,16 @@ function WPCAMat(data, opt = {}) {
|
|
|
16
17
|
|
|
17
18
|
//scale
|
|
18
19
|
let scale = get(opt, 'scale')
|
|
19
|
-
if (!
|
|
20
|
+
if (!isbol(scale)) {
|
|
20
21
|
scale = true //true: divide by the standard deviation
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
//nCompNIPALS
|
|
24
25
|
let nCompNIPALS = get(opt, 'nCompNIPALS')
|
|
25
|
-
if (!
|
|
26
|
+
if (!isnum(nCompNIPALS)) {
|
|
26
27
|
nCompNIPALS = 2 //with NIPALS. 指定PCA降維后的特徵數, 也就是降維后的維度
|
|
27
28
|
}
|
|
29
|
+
nCompNIPALS = cint(nCompNIPALS)
|
|
28
30
|
|
|
29
31
|
//n
|
|
30
32
|
let n = size(get(data, 0, []))
|
|
@@ -36,7 +38,7 @@ function WPCAMat(data, opt = {}) {
|
|
|
36
38
|
|
|
37
39
|
//check
|
|
38
40
|
if (nCompNIPALS > n) {
|
|
39
|
-
throw new Error(
|
|
41
|
+
throw new Error(`nCompNIPALS[${nCompNIPALS}] is more than the dimension[${n}] of data`)
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
//pca
|
package/test/cluster.test.mjs
CHANGED
|
@@ -12,7 +12,7 @@ describe(`cluster`, function() {
|
|
|
12
12
|
[80, 70, 90],
|
|
13
13
|
[50, 60, 80]
|
|
14
14
|
]
|
|
15
|
-
let clmat = { 'keys': null, 'ginds': [[2], [0, 1, 3]], 'gltdt': [[[80, 70, 90]], [[40, 50, 60], [50, 70, 60], [50, 60, 80]]], 'gmat': [[[77.39502404588043, 70.65388036857387
|
|
15
|
+
let clmat = { 'keys': null, 'ginds': [[2], [0, 1, 3]], 'gltdt': [[[80, 70, 90]], [[40, 50, 60], [50, 70, 60], [50, 60, 80]]], 'gmat': [[[77.39502404588043, 70.65388036857387]], [[36.76572825085965, 50.81184119955175], [50.520478881706346, 69.86935352609807], [55.318768821553576, 58.66492490577632]]] }
|
|
16
16
|
|
|
17
17
|
it(`should return '${JSON.stringify(clmat)}' when input ${JSON.stringify(mat)}, { mode, kNumber: 2, nCompNIPALS: 2 }`, async function() {
|
|
18
18
|
let r = await WCluster.cluster(mat, { mode, kNumber: 2, nCompNIPALS: 2 })
|
|
@@ -25,7 +25,7 @@ describe(`cluster`, function() {
|
|
|
25
25
|
{ name: 'Paul', a: 80, b: 70, c: 90 },
|
|
26
26
|
{ name: 'Fawcett', a: 50, b: 60, c: 80 },
|
|
27
27
|
]
|
|
28
|
-
let clltdt = { '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 }]], 'gmat': [[[77.39502404588043, 70.65388036857387
|
|
28
|
+
let clltdt = { '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 }]], 'gmat': [[[77.39502404588043, 70.65388036857387]], [[36.76572825085965, 50.81184119955175], [50.520478881706346, 69.86935352609807], [55.318768821553576, 58.66492490577632]]] }
|
|
29
29
|
|
|
30
30
|
it(`should return '${JSON.stringify(clltdt)}' when input ${JSON.stringify(ltdt)}, { mode, kNumber: 2, nCompNIPALS: 2 }`, async function() {
|
|
31
31
|
let r = await WCluster.cluster(ltdt, { mode, kNumber: 2, nCompNIPALS: 2 })
|
package/toolg/gDistRollup.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import rollupFiles from 'w-package-tools/src/rollupFiles.mjs'
|
|
3
3
|
import rollupWorker from 'w-package-tools/src/rollupWorker.mjs'
|
|
4
|
-
import rollupWorkerCore from 'w-package-tools/src/rollupWorkerCore.mjs'
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
let fdSrc = './src'
|
|
@@ -10,21 +9,21 @@ let fdTar = './dist'
|
|
|
10
9
|
|
|
11
10
|
async function rp() {
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
await rollupFiles({ //rollupFiles預設會clean folder
|
|
13
|
+
fns: 'WCluster.mjs',
|
|
14
|
+
fdSrc,
|
|
15
|
+
fdTar,
|
|
16
|
+
nameDistType: 'kebabCase',
|
|
17
|
+
// bNodePolyfill: true,
|
|
18
|
+
// bMinify: false,
|
|
19
|
+
globals: {
|
|
20
|
+
},
|
|
21
|
+
external: [
|
|
22
|
+
],
|
|
23
|
+
})
|
|
24
|
+
.catch((err) => {
|
|
25
|
+
console.log(err)
|
|
26
|
+
})
|
|
28
27
|
|
|
29
28
|
await rollupWorker({
|
|
30
29
|
name: 'WCluster', //原模組名稱, 將來會掛於winodw下
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-tw">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta http-equiv="content-type" content="text/html charset=UTF-8" />
|
|
6
|
-
<title>w-cluster cluster for k-medoids</title>
|
|
7
|
-
|
|
8
|
-
<!-- @babel/polyfill已廢棄 -->
|
|
9
|
-
<script nomodule src="https://cdn.jsdelivr.net/npm/@babel/polyfill@7.12.1/dist/polyfill.min.js"></script>
|
|
10
|
-
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/wsemi/dist/wsemi.umd.js"></script>
|
|
12
|
-
|
|
13
|
-
<script src="https://code.highcharts.com/highcharts.js"></script>
|
|
14
|
-
|
|
15
|
-
<script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.8/dist/w-cluster.umd.js"></script>
|
|
16
|
-
|
|
17
|
-
<script>
|
|
18
|
-
let dataIris=[{"class":"setosa","x1":5.1,"x2":3.5,"x3":1.4,"x4":0.2},{"class":"setosa","x1":4.9,"x2":3,"x3":1.4,"x4":0.2},{"class":"setosa","x1":4.7,"x2":3.2,"x3":1.3,"x4":0.2},{"class":"setosa","x1":4.6,"x2":3.1,"x3":1.5,"x4":0.2},{"class":"setosa","x1":5,"x2":3.6,"x3":1.4,"x4":0.2},{"class":"setosa","x1":5.4,"x2":3.9,"x3":1.7,"x4":0.4},{"class":"setosa","x1":4.6,"x2":3.4,"x3":1.4,"x4":0.3},{"class":"setosa","x1":5,"x2":3.4,"x3":1.5,"x4":0.2},{"class":"setosa","x1":4.4,"x2":2.9,"x3":1.4,"x4":0.2},{"class":"setosa","x1":4.9,"x2":3.1,"x3":1.5,"x4":0.1},{"class":"setosa","x1":5.4,"x2":3.7,"x3":1.5,"x4":0.2},{"class":"setosa","x1":4.8,"x2":3.4,"x3":1.6,"x4":0.2},{"class":"setosa","x1":4.8,"x2":3,"x3":1.4,"x4":0.1},{"class":"setosa","x1":4.3,"x2":3,"x3":1.1,"x4":0.1},{"class":"setosa","x1":5.8,"x2":4,"x3":1.2,"x4":0.2},{"class":"setosa","x1":5.7,"x2":4.4,"x3":1.5,"x4":0.4},{"class":"setosa","x1":5.4,"x2":3.9,"x3":1.3,"x4":0.4},{"class":"setosa","x1":5.1,"x2":3.5,"x3":1.4,"x4":0.3},{"class":"setosa","x1":5.7,"x2":3.8,"x3":1.7,"x4":0.3},{"class":"setosa","x1":5.1,"x2":3.8,"x3":1.5,"x4":0.3},{"class":"setosa","x1":5.4,"x2":3.4,"x3":1.7,"x4":0.2},{"class":"setosa","x1":5.1,"x2":3.7,"x3":1.5,"x4":0.4},{"class":"setosa","x1":4.6,"x2":3.6,"x3":1,"x4":0.2},{"class":"setosa","x1":5.1,"x2":3.3,"x3":1.7,"x4":0.5},{"class":"setosa","x1":4.8,"x2":3.4,"x3":1.9,"x4":0.2},{"class":"setosa","x1":5,"x2":3,"x3":1.6,"x4":0.2},{"class":"setosa","x1":5,"x2":3.4,"x3":1.6,"x4":0.4},{"class":"setosa","x1":5.2,"x2":3.5,"x3":1.5,"x4":0.2},{"class":"setosa","x1":5.2,"x2":3.4,"x3":1.4,"x4":0.2},{"class":"setosa","x1":4.7,"x2":3.2,"x3":1.6,"x4":0.2},{"class":"setosa","x1":4.8,"x2":3.1,"x3":1.6,"x4":0.2},{"class":"setosa","x1":5.4,"x2":3.4,"x3":1.5,"x4":0.4},{"class":"setosa","x1":5.2,"x2":4.1,"x3":1.5,"x4":0.1},{"class":"setosa","x1":5.5,"x2":4.2,"x3":1.4,"x4":0.2},{"class":"setosa","x1":4.9,"x2":3.1,"x3":1.5,"x4":0.2},{"class":"setosa","x1":5,"x2":3.2,"x3":1.2,"x4":0.2},{"class":"setosa","x1":5.5,"x2":3.5,"x3":1.3,"x4":0.2},{"class":"setosa","x1":4.9,"x2":3.6,"x3":1.4,"x4":0.1},{"class":"setosa","x1":4.4,"x2":3,"x3":1.3,"x4":0.2},{"class":"setosa","x1":5.1,"x2":3.4,"x3":1.5,"x4":0.2},{"class":"setosa","x1":5,"x2":3.5,"x3":1.3,"x4":0.3},{"class":"setosa","x1":4.5,"x2":2.3,"x3":1.3,"x4":0.3},{"class":"setosa","x1":4.4,"x2":3.2,"x3":1.3,"x4":0.2},{"class":"setosa","x1":5,"x2":3.5,"x3":1.6,"x4":0.6},{"class":"setosa","x1":5.1,"x2":3.8,"x3":1.9,"x4":0.4},{"class":"setosa","x1":4.8,"x2":3,"x3":1.4,"x4":0.3},{"class":"setosa","x1":5.1,"x2":3.8,"x3":1.6,"x4":0.2},{"class":"setosa","x1":4.6,"x2":3.2,"x3":1.4,"x4":0.2},{"class":"setosa","x1":5.3,"x2":3.7,"x3":1.5,"x4":0.2},{"class":"setosa","x1":5,"x2":3.3,"x3":1.4,"x4":0.2},{"class":"versicolor","x1":7,"x2":3.2,"x3":4.7,"x4":1.4},{"class":"versicolor","x1":6.4,"x2":3.2,"x3":4.5,"x4":1.5},{"class":"versicolor","x1":6.9,"x2":3.1,"x3":4.9,"x4":1.5},{"class":"versicolor","x1":5.5,"x2":2.3,"x3":4,"x4":1.3},{"class":"versicolor","x1":6.5,"x2":2.8,"x3":4.6,"x4":1.5},{"class":"versicolor","x1":5.7,"x2":2.8,"x3":4.5,"x4":1.3},{"class":"versicolor","x1":6.3,"x2":3.3,"x3":4.7,"x4":1.6},{"class":"versicolor","x1":4.9,"x2":2.4,"x3":3.3,"x4":1},{"class":"versicolor","x1":6.6,"x2":2.9,"x3":4.6,"x4":1.3},{"class":"versicolor","x1":5.2,"x2":2.7,"x3":3.9,"x4":1.4},{"class":"versicolor","x1":5,"x2":2,"x3":3.5,"x4":1},{"class":"versicolor","x1":5.9,"x2":3,"x3":4.2,"x4":1.5},{"class":"versicolor","x1":6,"x2":2.2,"x3":4,"x4":1},{"class":"versicolor","x1":6.1,"x2":2.9,"x3":4.7,"x4":1.4},{"class":"versicolor","x1":5.6,"x2":2.9,"x3":3.6,"x4":1.3},{"class":"versicolor","x1":6.7,"x2":3.1,"x3":4.4,"x4":1.4},{"class":"versicolor","x1":5.6,"x2":3,"x3":4.5,"x4":1.5},{"class":"versicolor","x1":5.8,"x2":2.7,"x3":4.1,"x4":1},{"class":"versicolor","x1":6.2,"x2":2.2,"x3":4.5,"x4":1.5},{"class":"versicolor","x1":5.6,"x2":2.5,"x3":3.9,"x4":1.1},{"class":"versicolor","x1":5.9,"x2":3.2,"x3":4.8,"x4":1.8},{"class":"versicolor","x1":6.1,"x2":2.8,"x3":4,"x4":1.3},{"class":"versicolor","x1":6.3,"x2":2.5,"x3":4.9,"x4":1.5},{"class":"versicolor","x1":6.1,"x2":2.8,"x3":4.7,"x4":1.2},{"class":"versicolor","x1":6.4,"x2":2.9,"x3":4.3,"x4":1.3},{"class":"versicolor","x1":6.6,"x2":3,"x3":4.4,"x4":1.4},{"class":"versicolor","x1":6.8,"x2":2.8,"x3":4.8,"x4":1.4},{"class":"versicolor","x1":6.7,"x2":3,"x3":5,"x4":1.7},{"class":"versicolor","x1":6,"x2":2.9,"x3":4.5,"x4":1.5},{"class":"versicolor","x1":5.7,"x2":2.6,"x3":3.5,"x4":1},{"class":"versicolor","x1":5.5,"x2":2.4,"x3":3.8,"x4":1.1},{"class":"versicolor","x1":5.5,"x2":2.4,"x3":3.7,"x4":1},{"class":"versicolor","x1":5.8,"x2":2.7,"x3":3.9,"x4":1.2},{"class":"versicolor","x1":6,"x2":2.7,"x3":5.1,"x4":1.6},{"class":"versicolor","x1":5.4,"x2":3,"x3":4.5,"x4":1.5},{"class":"versicolor","x1":6,"x2":3.4,"x3":4.5,"x4":1.6},{"class":"versicolor","x1":6.7,"x2":3.1,"x3":4.7,"x4":1.5},{"class":"versicolor","x1":6.3,"x2":2.3,"x3":4.4,"x4":1.3},{"class":"versicolor","x1":5.6,"x2":3,"x3":4.1,"x4":1.3},{"class":"versicolor","x1":5.5,"x2":2.5,"x3":4,"x4":1.3},{"class":"versicolor","x1":5.5,"x2":2.6,"x3":4.4,"x4":1.2},{"class":"versicolor","x1":6.1,"x2":3,"x3":4.6,"x4":1.4},{"class":"versicolor","x1":5.8,"x2":2.6,"x3":4,"x4":1.2},{"class":"versicolor","x1":5,"x2":2.3,"x3":3.3,"x4":1},{"class":"versicolor","x1":5.6,"x2":2.7,"x3":4.2,"x4":1.3},{"class":"versicolor","x1":5.7,"x2":3,"x3":4.2,"x4":1.2},{"class":"versicolor","x1":5.7,"x2":2.9,"x3":4.2,"x4":1.3},{"class":"versicolor","x1":6.2,"x2":2.9,"x3":4.3,"x4":1.3},{"class":"versicolor","x1":5.1,"x2":2.5,"x3":3,"x4":1.1},{"class":"versicolor","x1":5.7,"x2":2.8,"x3":4.1,"x4":1.3},{"class":"virginica","x1":6.3,"x2":3.3,"x3":6,"x4":2.5},{"class":"virginica","x1":5.8,"x2":2.7,"x3":5.1,"x4":1.9},{"class":"virginica","x1":7.1,"x2":3,"x3":5.9,"x4":2.1},{"class":"virginica","x1":6.3,"x2":2.9,"x3":5.6,"x4":1.8},{"class":"virginica","x1":6.5,"x2":3,"x3":5.8,"x4":2.2},{"class":"virginica","x1":7.6,"x2":3,"x3":6.6,"x4":2.1},{"class":"virginica","x1":4.9,"x2":2.5,"x3":4.5,"x4":1.7},{"class":"virginica","x1":7.3,"x2":2.9,"x3":6.3,"x4":1.8},{"class":"virginica","x1":6.7,"x2":2.5,"x3":5.8,"x4":1.8},{"class":"virginica","x1":7.2,"x2":3.6,"x3":6.1,"x4":2.5},{"class":"virginica","x1":6.5,"x2":3.2,"x3":5.1,"x4":2},{"class":"virginica","x1":6.4,"x2":2.7,"x3":5.3,"x4":1.9},{"class":"virginica","x1":6.8,"x2":3,"x3":5.5,"x4":2.1},{"class":"virginica","x1":5.7,"x2":2.5,"x3":5,"x4":2},{"class":"virginica","x1":5.8,"x2":2.8,"x3":5.1,"x4":2.4},{"class":"virginica","x1":6.4,"x2":3.2,"x3":5.3,"x4":2.3},{"class":"virginica","x1":6.5,"x2":3,"x3":5.5,"x4":1.8},{"class":"virginica","x1":7.7,"x2":3.8,"x3":6.7,"x4":2.2},{"class":"virginica","x1":7.7,"x2":2.6,"x3":6.9,"x4":2.3},{"class":"virginica","x1":6,"x2":2.2,"x3":5,"x4":1.5},{"class":"virginica","x1":6.9,"x2":3.2,"x3":5.7,"x4":2.3},{"class":"virginica","x1":5.6,"x2":2.8,"x3":4.9,"x4":2},{"class":"virginica","x1":7.7,"x2":2.8,"x3":6.7,"x4":2},{"class":"virginica","x1":6.3,"x2":2.7,"x3":4.9,"x4":1.8},{"class":"virginica","x1":6.7,"x2":3.3,"x3":5.7,"x4":2.1},{"class":"virginica","x1":7.2,"x2":3.2,"x3":6,"x4":1.8},{"class":"virginica","x1":6.2,"x2":2.8,"x3":4.8,"x4":1.8},{"class":"virginica","x1":6.1,"x2":3,"x3":4.9,"x4":1.8},{"class":"virginica","x1":6.4,"x2":2.8,"x3":5.6,"x4":2.1},{"class":"virginica","x1":7.2,"x2":3,"x3":5.8,"x4":1.6},{"class":"virginica","x1":7.4,"x2":2.8,"x3":6.1,"x4":1.9},{"class":"virginica","x1":7.9,"x2":3.8,"x3":6.4,"x4":2},{"class":"virginica","x1":6.4,"x2":2.8,"x3":5.6,"x4":2.2},{"class":"virginica","x1":6.3,"x2":2.8,"x3":5.1,"x4":1.5},{"class":"virginica","x1":6.1,"x2":2.6,"x3":5.6,"x4":1.4},{"class":"virginica","x1":7.7,"x2":3,"x3":6.1,"x4":2.3},{"class":"virginica","x1":6.3,"x2":3.4,"x3":5.6,"x4":2.4},{"class":"virginica","x1":6.4,"x2":3.1,"x3":5.5,"x4":1.8},{"class":"virginica","x1":6,"x2":3,"x3":4.8,"x4":1.8},{"class":"virginica","x1":6.9,"x2":3.1,"x3":5.4,"x4":2.1},{"class":"virginica","x1":6.7,"x2":3.1,"x3":5.6,"x4":2.4},{"class":"virginica","x1":6.9,"x2":3.1,"x3":5.1,"x4":2.3},{"class":"virginica","x1":5.8,"x2":2.7,"x3":5.1,"x4":1.9},{"class":"virginica","x1":6.8,"x2":3.2,"x3":5.9,"x4":2.3},{"class":"virginica","x1":6.7,"x2":3.3,"x3":5.7,"x4":2.5},{"class":"virginica","x1":6.7,"x2":3,"x3":5.2,"x4":2.3},{"class":"virginica","x1":6.3,"x2":2.5,"x3":5,"x4":1.9},{"class":"virginica","x1":6.5,"x2":3,"x3":5.2,"x4":2},{"class":"virginica","x1":6.2,"x2":3.4,"x3":5.4,"x4":2.3},{"class":"virginica","x1":5.9,"x2":3,"x3":5.1,"x4":1.8}]
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
</head>
|
|
22
|
-
|
|
23
|
-
<body>
|
|
24
|
-
|
|
25
|
-
<div style="display:flex;">
|
|
26
|
-
<div style="margin-right:5px;">kNumber:</div>
|
|
27
|
-
<select id="kNumber" style="width:50px; margin-right:15px;" onchange="cls()">
|
|
28
|
-
<option value="2">2</option>
|
|
29
|
-
<option value="3" selected>3</option>
|
|
30
|
-
<option value="4">4</option>
|
|
31
|
-
<option value="5">5</option>
|
|
32
|
-
<option value="6">6</option>
|
|
33
|
-
<option value="7">7</option>
|
|
34
|
-
<option value="8">8</option>
|
|
35
|
-
<option value="9">9</option>
|
|
36
|
-
<option value="10">10</option>
|
|
37
|
-
</select>
|
|
38
|
-
<div style="margin-right:5px;">nCompNIPALS:</div>
|
|
39
|
-
<select id="nCompNIPALS" style="width:50px; margin-right:15px;" onchange="cls()">
|
|
40
|
-
<option value="2" selected>2</option>
|
|
41
|
-
<option value="3">3</option>
|
|
42
|
-
<option value="4">4</option>
|
|
43
|
-
</select>
|
|
44
|
-
<div id="message"></div>
|
|
45
|
-
</div>
|
|
46
|
-
|
|
47
|
-
<div id="container" style="width:1000px; height:600px;"></div>
|
|
48
|
-
|
|
49
|
-
<script>
|
|
50
|
-
|
|
51
|
-
let WCluster = window['w-cluster']
|
|
52
|
-
console.log(WCluster)
|
|
53
|
-
|
|
54
|
-
function cls(){
|
|
55
|
-
|
|
56
|
-
let kNumber = wsemi.cint(document.querySelector('#kNumber option:checked').value)
|
|
57
|
-
console.log('kNumber',kNumber)
|
|
58
|
-
|
|
59
|
-
let nCompNIPALS = wsemi.cint(document.querySelector('#nCompNIPALS option:checked').value)
|
|
60
|
-
console.log('nCompNIPALS',nCompNIPALS)
|
|
61
|
-
|
|
62
|
-
document.querySelector('#message').innerHTML = 'analysing...'
|
|
63
|
-
|
|
64
|
-
wsemi.delay(100)
|
|
65
|
-
.then(function (){
|
|
66
|
-
|
|
67
|
-
WCluster.cluster(dataIris, { kNumber: kNumber, nCompNIPALS: nCompNIPALS, mode: 'k-medoids' })
|
|
68
|
-
.then(function(res){
|
|
69
|
-
console.log('res',res)
|
|
70
|
-
|
|
71
|
-
let ds=[]
|
|
72
|
-
for(let g=0;g<res.gmat.length;g++){
|
|
73
|
-
let vs=[]
|
|
74
|
-
for(let j=0;j<res.gmat[g].length;j++){
|
|
75
|
-
vs.push({
|
|
76
|
-
x:res.gmat[g][j][0],
|
|
77
|
-
y:res.gmat[g][j][1],
|
|
78
|
-
label:res.gltdt[g][j].class,
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
ds.push({
|
|
82
|
-
name:'group'+(g+1),
|
|
83
|
-
data:vs,
|
|
84
|
-
dataLabels: {
|
|
85
|
-
enabled: true,
|
|
86
|
-
formatter: function() {
|
|
87
|
-
return this.point.label
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
console.log('ds',ds)
|
|
94
|
-
|
|
95
|
-
Highcharts.chart('container', {
|
|
96
|
-
chart: {
|
|
97
|
-
animation: false,
|
|
98
|
-
type: 'scatter',
|
|
99
|
-
},
|
|
100
|
-
plotOptions: {
|
|
101
|
-
scatter: {
|
|
102
|
-
animation: false
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
title: {
|
|
106
|
-
text: ''
|
|
107
|
-
},
|
|
108
|
-
xAxis: {
|
|
109
|
-
title: {
|
|
110
|
-
text: ''
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
yAxis: {
|
|
114
|
-
title: {
|
|
115
|
-
text: ''
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
series: ds,
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
})
|
|
122
|
-
.catch(function(err) {
|
|
123
|
-
console.log(err)
|
|
124
|
-
})
|
|
125
|
-
.finally(function() {
|
|
126
|
-
document.querySelector('#message').innerHTML = 'done'
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
cls()
|
|
133
|
-
|
|
134
|
-
</script>
|
|
135
|
-
|
|
136
|
-
</body>
|
|
137
|
-
|
|
138
|
-
</html>
|