-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
37 lines (28 loc) · 1.14 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import XMeans from './index';
const expect = require('chai').expect
describe('xmeans clustering', () => {
it('should cluster data using xmeans', () => {
let inputData = [[0], [0], [10], [10], [20], [20]];
let xmeansInstance = new XMeans(inputData, [[0.5], [10]], 20, 0.025);
xmeansInstance.process();
expect(xmeansInstance.clusters.length).to.eql(3);
expect(xmeansInstance.centers.length).to.eql(3);
expect(xmeansInstance.getClusterData()).to.eql([
[[0], [0]],
[[10], [10]],
[[20], [20]]
]);
});
it('should cluster 2 dimensional data using xmeans', () => {
let inputData = [[0, 0], [0, 0], [0, 0], [0, 0], [10, 10], [10, 10], [10, 10], [20, 20], [20, 20], [20, 20]];
let x = new XMeans(inputData, [[0, 0], [5, 5]], 20, 0.025);
x.process();
expect(x.clusters.length).to.eql(3);
expect(x.centers.length).to.eql(3);
expect(x.getClusterData()).to.eql([
[[0, 0], [0, 0], [0, 0], [0, 0]],
[[10, 10], [10, 10], [10, 10]],
[[20, 20], [20, 20], [20, 20]]
]);
});
});