From 9be1c6cef0c4e1bc8ca724dca1c67a1b276f9540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20Soko=C5=82owski?= Date: Mon, 10 May 2021 02:11:36 +0200 Subject: [PATCH] fix confusion matrix for tsp weight --- src/components/ConfusionMatrix/Table.jsx | 4 +-- src/components/ConfusionMatrix/index.jsx | 11 ++----- src/components/Navigation/index.jsx | 2 +- src/utils/predict.js | 41 +++++++++++------------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/components/ConfusionMatrix/Table.jsx b/src/components/ConfusionMatrix/Table.jsx index 795cec4..f374eb2 100644 --- a/src/components/ConfusionMatrix/Table.jsx +++ b/src/components/ConfusionMatrix/Table.jsx @@ -27,7 +27,7 @@ function TableComponent({ confusionMatrix, headers }) { - Actual + PREDICT @@ -53,7 +53,7 @@ function TableComponent({ confusionMatrix, headers }) { //padding: '2px', }} > - Predict + ACTUAL ) : ( <> diff --git a/src/components/ConfusionMatrix/index.jsx b/src/components/ConfusionMatrix/index.jsx index 1d3ba73..de56b71 100644 --- a/src/components/ConfusionMatrix/index.jsx +++ b/src/components/ConfusionMatrix/index.jsx @@ -50,19 +50,15 @@ function ConfusionMatrix({ tree, onChange, data, allClasses, categoryAttr, disab } useEffect(() => { - //console.log(allClasses); + console.log('use effect confusion matrix'); let CM = buildArray(allClasses.length); - // console.log(CM); - // console.log(categoryAttr); - // console.log(tree); - // console.log(data); if (!disabled && tree !== null) { let prediction, clazz; for (let index = 0; index < data.length; index++) { + //for (let index = 100; index < 102; index++) { prediction = predict(tree, data[index]); clazz = data[index][categoryAttr]; - //console.log(prediction, clazz); if (prediction === clazz) { CM[allClasses.indexOf(clazz)][allClasses.indexOf(clazz)]++; @@ -74,9 +70,8 @@ function ConfusionMatrix({ tree, onChange, data, allClasses, categoryAttr, disab let tmpAccuracy = handleAccuracy(CM); setAccuracy(tmpAccuracy); onChange(tmpAccuracy); - //console.log(CM); } - }, [tree, disabled, allClasses, categoryAttr, data]); + }, [tree, disabled, allClasses, categoryAttr, data, onChange]); function buildArray(lenght) { let arr = []; diff --git a/src/components/Navigation/index.jsx b/src/components/Navigation/index.jsx index dbe2750..d46b5fe 100644 --- a/src/components/Navigation/index.jsx +++ b/src/components/Navigation/index.jsx @@ -233,7 +233,7 @@ function Navigation({ onPrepareConfig }) { - Entropy threshold + Entropy thres. =', - // tree.predicateName === '==', - // tree.predicateName === '<' - // ); - if (tree.weight) { - attr1 = tree.attr2; - attr2 = tree.pivot; - value = item[attr1]; - pivot = item[attr2]; - predicate = predicates['w']; - match = predicate(value, pivot, tree.weight); - - // console.log('predict - waga', match); - } if (tree.predicateName === '>=' || tree.predicateName === '==') { attr1 = tree.attr2; value = item[attr1]; @@ -31,18 +15,30 @@ export function predict(tree, item) { predicate = predicates[tree.predicateName]; match = predicate(value, pivot); - // console.log('predict - c45', match); + //console.log('predict - c45', match); } if (tree.predicateName === '<') { attr1 = tree.attr2; attr2 = tree.pivot; - value = item[attr1]; - pivot = item[attr2]; + value = parseFloat(item[attr1]); + pivot = parseFloat(item[attr2]); predicate = predicates[tree.predicateName]; match = predicate(value, pivot); - // console.log('predict - tsp', match); + //console.log('predict - tsp', match); + } + if (tree.weight) { + console.log(tree.weight); + attr1 = tree.attr2; + attr2 = tree.pivot; + value = parseFloat(item[attr1]); + pivot = parseFloat(item[attr2]); + + predicate = predicates['w']; + match = predicate(value, pivot, tree.weight); + + //console.log('predict - waga', match, value + '<', pivot * tree.weight); } // move to one of subtrees @@ -64,6 +60,7 @@ var predicates = { return a < b; }, w: function (a, b, w) { + //console.log(a < w * b, a, w * b); return a < w * b; }, };