From 6d5ccb91b96eda7248f99969e866f2f5e811b496 Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:15:36 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-kmn1.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/test-kmn1.js 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))