Tue 27 Aug 00:14:56 CEST 2024
This commit is contained in:
parent
d4fab142b6
commit
6d5ccb91b9
30
test/test-kmn1.js
Normal file
30
test/test-kmn1.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
var data = [[1,0,1,0,1,1,1,0,0,0,0,0,1,0],
|
||||
[1,1,1,1,1,1,1,0,0,0,0,0,1,0],
|
||||
[1,1,1,0,1,1,1,0,1,0,0,0,1,0],
|
||||
[1,0,1,1,1,1,1,1,0,0,0,0,1,0],
|
||||
[1,1,1,1,1,1,1,0,0,0,0,0,1,1],
|
||||
[0,0,1,0,0,1,0,0,1,0,1,1,1,0],
|
||||
[0,0,0,0,0,0,1,1,1,0,1,1,1,0],
|
||||
[0,0,0,0,0,1,1,1,0,1,0,1,1,0],
|
||||
[0,0,1,0,1,0,1,1,1,1,0,1,1,1],
|
||||
[0,0,0,0,0,0,1,1,1,1,1,1,1,1],
|
||||
[1,0,1,0,0,1,1,1,1,1,0,0,1,0]
|
||||
];
|
||||
|
||||
var model = ml.learn({
|
||||
algorithm: ml.ML.KMN,
|
||||
data : data,
|
||||
k : 4,
|
||||
epochs: 100,
|
||||
|
||||
distance : {type : "pearson"}
|
||||
// default : {type : 'euclidean'}
|
||||
// {type : 'pearson'}
|
||||
// Or you can use your own distance function
|
||||
// distance : function(vecx, vecy) {return Math.abs(dot(vecx,vecy));}
|
||||
});
|
||||
print(toJSON(model).length+' Bytes')
|
||||
|
||||
print("clusters : ", model.clusters);
|
||||
print("means : ", model.means);
|
||||
print(ml.classify(model))
|
Loading…
Reference in New Issue
Block a user