jam/test/test-id3.js

32 lines
958 B
JavaScript

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