From 3a03cb2cdacc0c663c8173166acc7103b2eb1c05 Mon Sep 17 00:00:00 2001 From: sbosse Date: Tue, 27 Aug 2024 00:15:57 +0200 Subject: [PATCH] Tue 27 Aug 00:14:56 CEST 2024 --- test/test-rf2.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/test-rf2.js diff --git a/test/test-rf2.js b/test/test-rf2.js new file mode 100644 index 0000000..bfb173b --- /dev/null +++ b/test/test-rf2.js @@ -0,0 +1,34 @@ +var data = load('test-data-iris.json') + +var datac = ml.preprocess(data,'xmy',{features:['length','width','petal_length','petal_width'], + target:'species'}); +// print(datac) +var labels = [ + 'setosa', + 'versicolor', + 'virginica' +] +var x = datac.x; +var y = datac.y; + +var t0=time() +var model = ml.learn({ + algorithm:ml.ML.RF, + labels:labels, + numTrees:5, + maxDepth:10, + numTries:10, + weakType:false, + x:x, + y:y, + }); + +var t1=time() +var result = ml.classify(model,x).map(ml.best).map(function (r,i) { r.y=y[i]; return r } ) +var t2=time() +print(result) +var correct=0,wrong=0; +result.forEach(function (r) { if (r.value==r.y) correct++; else wrong++ }); +print('Correct='+correct+', wrong='+wrong); +print(toJSON(model).length) +print(t1-t0,t2-t1)