jam/test/test-kmn1.js

31 lines
941 B
JavaScript
Raw Normal View History

2024-08-27 00:15:36 +02:00
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))