diff --git a/test/test-kmn1.js b/test/test-kmn1.js new file mode 100644 index 0000000..9f6ebf7 --- /dev/null +++ b/test/test-kmn1.js @@ -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))