{category ? (
diff --git a/src/components/Tree.jsx b/src/components/Tree.jsx
index e30fbc3..4b3d404 100644
--- a/src/components/Tree.jsx
+++ b/src/components/Tree.jsx
@@ -22,6 +22,7 @@ import { executeAlgorithm } from '../utils/algorithm-executor';
import TestSetFileReader from './TestSetFileReader';
import ConfusionMatrix from './ConfusionMatrix';
import { getSizeTree } from '../utils/size-checker';
+import { testTree } from '../services/playground3';
/**
* @typedef {import('../utils/decision-tree.js').DecisionTreeBuilder} DecisionTreeBuilder
@@ -45,14 +46,16 @@ const Tree = ({ options }) => {
const [accuracyTraining, setAccuracyTraining] = useState(0);
const [accuracyTest, setAccuracyTest] = useState(0);
const [root, setRoot] = useState(null);
+ const [secondRoot, setSecondRoot] = useState(null);
const [sizeTree, setSizeTree] = useState({ joints: 0, leafs: 0 });
- const [testSet, setTestSet] = useState([]);
+ const [testSet, setTestSet] = useState(null);
const [showTestTree, setShowTestTree] = useState(false);
const { isLoading, setIsLoading } = useLoadingContext();
useEffect(() => {
setRoot(null);
setIsLoading(true);
+ setTestSet(null);
let terminated = false;
executeAlgorithm(options)
.then(value => {
@@ -60,6 +63,7 @@ const Tree = ({ options }) => {
return;
}
setRoot(value);
+ updateTestTree(value);
})
.catch(e => console.error(e))
.finally(() => {
@@ -82,13 +86,33 @@ const Tree = ({ options }) => {
//setAccuracy(Math.random() * 10);
}, [root]);
- const requestChildChange = newRoot => setRoot(newRoot);
+ const requestChildChange = newRoot => {
+ setRoot(newRoot);
+ updateTestTree(newRoot);
+ };
function handleGetTestSet({ data }) {
setTestSet(data);
}
+
+ function updateTestTree(newRoot) {
+ console.log(options.categoryAttr);
+ let tmpRoot = JSON.parse(JSON.stringify(newRoot));
+ if (testSet == null) {
+ testTree(tmpRoot, options.trainingSet, options.categoryAttr);
+ console.log(tmpRoot);
+ setSecondRoot(tmpRoot);
+ } else {
+ testTree(tmpRoot, testSet, options.categoryAttr);
+ console.log(tmpRoot);
+ setSecondRoot(tmpRoot);
+ }
+ }
+
function handleShowTestTree(e) {
+ console.log(e);
setShowTestTree(e.target.checked);
+ //updateTestTree(root);
}
return (
@@ -193,7 +217,7 @@ const Tree = ({ options }) => {
Show test tree
-
+
handleShowTestTree(e)} />
@@ -211,7 +235,16 @@ const Tree = ({ options }) => {
Test tree
- {}} requestChildChange={requestChildChange} side={true} />
+ {showTestTree ? (
+ {}}
+ //requestChildChange={requestChildChange}
+ side={true}
+ />
+ ) : (
+
+ )}
)}
diff --git a/src/services/playground3.js b/src/services/playground3.js
new file mode 100644
index 0000000..c35b3a6
--- /dev/null
+++ b/src/services/playground3.js
@@ -0,0 +1,62 @@
+export function testTree(tree, newData, categoryAttr) {
+ let predicate;
+ console.log(categoryAttr);
+ if (tree.category) {
+ tree.trainingSet2 = newData;
+ let _positiveCounter = 0,
+ _quality = 0;
+ for (let element of newData) {
+ if (element[categoryAttr] === tree.category) _positiveCounter++;
+ }
+ let _negativeCounter = newData.length - _positiveCounter;
+ _quality = _positiveCounter / newData.length;
+ _quality = _quality * 100;
+
+ tree.quality = _quality.toFixed(2);
+ tree.matchedCount = _positiveCounter;
+ tree.notMatchedCount = _negativeCounter;
+ return;
+ } else {
+ tree.nodeSet = newData;
+
+ predicate = predicates[tree.predicateName];
+
+ let matchedData = [],
+ notMatchedData = [];
+
+ newData.forEach(x => {
+ let match;
+ if (tree.predicateName === '==' || tree.predicateName === '>=') {
+ match = predicate(x[tree.attr2], tree.pivot);
+ console.log('c45', match);
+ } else if (tree.weight) {
+ match = predicate(x[tree.attr2], x[tree.pivot], tree.weight);
+ console.log('tspw', match);
+ } else {
+ match = predicate(x[tree.attr2], x[tree.pivot]);
+ console.log('tsp', match);
+ }
+
+ match ? matchedData.push(x) : notMatchedData.push(x);
+ });
+
+ testTree(tree.match, matchedData, categoryAttr);
+ testTree(tree.notMatch, notMatchedData, categoryAttr);
+ }
+}
+
+var predicates = {
+ '==': function (a, b) {
+ return a === b;
+ },
+ '>=': function (a, b) {
+ return a >= b;
+ },
+ '<': function (a, b) {
+ return a < b;
+ },
+ w: function (a, b, w) {
+ //console.log(a < w * b, a, w * b);
+ return a < w * b;
+ },
+};