fix confusion matrix for tsp weight

This commit is contained in:
Hubert Sokołowski
2021-05-10 02:11:36 +02:00
parent df2a2741b5
commit 9be1c6cef0
4 changed files with 25 additions and 33 deletions

View File

@@ -27,7 +27,7 @@ function TableComponent({ confusionMatrix, headers }) {
<Thead>
<Tr>
<Th colSpan={confusionMatrix.length + 2} textAlign="center">
Actual
PREDICT
</Th>
</Tr>
<Tr>
@@ -53,7 +53,7 @@ function TableComponent({ confusionMatrix, headers }) {
//padding: '2px',
}}
>
Predict
ACTUAL
</Th>
) : (
<></>

View File

@@ -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 = [];

View File

@@ -233,7 +233,7 @@ function Navigation({ onPrepareConfig }) {
<WrapItem>
<FormControl id="entropy" width="auto">
<FormHelperText mb={2} mt={0}>
Entropy threshold
Entropy thres.
</FormHelperText>
<Box>
<FormControlNumberInput

View File

@@ -1,29 +1,13 @@
export function predict(tree, item) {
var attr1, attr2, value, predicate, pivot, match;
// Traversing tree from the root to leaf
while (true) {
if (tree?.category) {
if (tree.category) {
// only leafs contains predicted category
return tree.category;
}
// console.log(
// tree.predicateName,
// tree.weight,
// tree.predicateName === '>=',
// 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;
},
};