mirror of
https://github.com/hsokolowski/iTree.git
synced 2026-06-11 14:24:17 -04:00
fix confusion matrix for tsp weight
This commit is contained in:
@@ -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>
|
||||
) : (
|
||||
<></>
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user