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))