From da412a3a40f946f1f08e09560da607ea5eea5a22 Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:15:31 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-svm1.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/test-svm1.js diff --git a/test/test-svm1.js b/test/test-svm1.js new file mode 100644 index 0000000..2c69f1e --- /dev/null +++ b/test/test-svm1.js @@ -0,0 +1,46 @@ +var x = [[0.4, 0.5, 0.5, 0., 0., 0.], + [0.5, 0.3, 0.5, 0., 0., 0.01], + [0.4, 0.8, 0.5, 0., 0.1, 0.2], + [1.4, 0.5, 0.5, 0., 0., 0.], + [1.5, 0.3, 0.5, 0., 0., 0.], + [0., 0.9, 1.5, 0., 0., 0.], + [0., 0.7, 1.5, 0., 0., 0.], + [0.5, 0.1, 0.9, 0., -1.8, 0.], + [0.8, 0.8, 0.5, 0., 0., 0.], + [0., 0.9, 0.5, 0.3, 0.5, 0.2], + [0., 0., 0.5, 0.4, 0.5, 0.], + [0., 0., 0.5, 0.5, 0.5, 0.], + [0.3, 0.6, 0.7, 1.7, 1.3, -0.7], + [0., 0., 0.5, 0.3, 0.5, 0.2], + [0., 0., 0.5, 0.4, 0.5, 0.1], + [0., 0., 0.5, 0.5, 0.5, 0.01], + [0.2, 0.01, 0.5, 0., 0., 0.9], + [0., 0., 0.5, 0.3, 0.5, -2.3], + [0., 0., 0.5, 0.4, 0.5, 4], + [0., 0., 0.5, 0.5, 0.5, -2]]; +// Only binary classification here: Feature Y=-1->false, 1->true +var y = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,1,1,1,1,1]; + +var model = ml.learn({ + algorithm : ml.ML.SVM, + x : x, + y : y, + + C : 1, // default : 1.0. C in SVM. + tol : 1e-4, // default : 1e-4. Higher tolerance --> Higher precision + max_passes : 200, // default : 20. Higher max_passes --> Higher precision + alpha_tol : 1e-5, // default : 1e-5. Higher alpha_tolerance --> Higher precision + + //kernel : { type: "polynomial", c: 1, d: 5} + kernel : { type: "rbf", sigma:0.5 } +}); + +print(toJSON(model).length+' Bytes') + +// print(model) +a = [ + [1.3, 1.7, 0.5, 0.5, 1.5, 0.4], + [0.05, 0.1, 0.5, 0.7, 0.4, -1.4] +] +print(ml.classify(model,x)); +print(ml.classify(model,a));