From 5b883273cdb3c71a59ee0a04529de15756835e3c Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:15:30 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-id3.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/test-id3.js diff --git a/test/test-id3.js b/test/test-id3.js new file mode 100644 index 0000000..1974fc3 --- /dev/null +++ b/test/test-id3.js @@ -0,0 +1,31 @@ +var training_data = [ + {"color":"blue", "shape":"square", "liked":false}, + {"color":"red", "shape":"square", "liked":false}, + {"color":"blue", "shape":"circle", "liked":true}, + {"color":"red", "shape":"circle", "liked":true}, + {"color":"blue", "shape":"hexagon", "liked":false}, + {"color":"red", "shape":"hexagon", "liked":false}, + {"color":"yellow", "shape":"hexagon", "liked":true}, + {"color":"yellow", "shape":"circle", "liked":true} +] + +var test_data = [ + {"color":"blue", "shape":"hexagon", "liked":false}, + {"color":"red", "shape":"hexagon", "liked":false}, + {"color":"yellow", "shape":"hexagon", "liked":true}, + {"color":"yellow", "shape":"circle", "liked":true} + ]; + +var target = "liked"; +var features = ["color", "shape"]; +var model = ml.learn({ + algorithm:ml.ML.ID3, + data:training_data, + target:target, + features:features +}) + + +print(ml.print(model)) +print(toJSON(model).length+' Bytes') +print(ml.classify(model,test_data))