From 79c2af1c138f1b539da16c1171da7cd0ce88173f Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:14:59 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-id3-2.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/test-id3-2.js diff --git a/test/test-id3-2.js b/test/test-id3-2.js new file mode 100644 index 0000000..07d5269 --- /dev/null +++ b/test/test-id3-2.js @@ -0,0 +1,34 @@ +var data = load('test-data-iris.json') +var t0=time() +var target = "species"; +var features = ["length", "width","petal_length","petal_width"]; +var datac = ml.preprocess(data,'xy',{features:features,target:target}); + +var model = ml.learn({ + algorithm:ml.ML.ID3, + data:data, + target:target, + features:features +}) +var t1=time() +var result = ml.classify(model,datac.x).map(function (r,i) { + return {value:r,y:datac.y[i]}} ) +var t2=time() +var correct=0,wrong=0; +result.forEach(function (r) { if (r.value==r.y) correct++; else wrong++ }); +print('Training Data Test: Correct='+correct+', wrong='+wrong); +print(toJSON(model).length) +print(t1-t0,t2-t1) +datac.x = ml.noise(datac.x, + {length:0.2, + width:0.1, + petal_length:0.05, + petal_width:0.01 +}); + +// print(datac.x) +var result = ml.classify(model,datac.x).map(function (r,i) { + return {value:r,y:datac.y[i]}} ) +correct=0,wrong=0; +result.forEach(function (r) { if (r.value==r.y) correct++; else wrong++ }); +print('Test Data Test (Noise): Correct='+correct+', wrong='+wrong);