diff --git a/package-lock.json b/package-lock.json index 881f18f..a3e69e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16689,8 +16689,7 @@ "uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "optional": true + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" }, "uuid4": { "version": "1.1.4", diff --git a/package.json b/package.json index 755c8f6..c677212 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "react-scripts": "4.0.1", "react-select-search": "^2.2.4", "react-table": "^7.6.3", + "uuid": "^8.3.2", "web-vitals": "^0.2.4" }, "scripts": { diff --git a/src/components/ConfusionMatrix/Table.jsx b/src/components/ConfusionMatrix/Table.jsx index 1b2563f..8d6dc4c 100644 --- a/src/components/ConfusionMatrix/Table.jsx +++ b/src/components/ConfusionMatrix/Table.jsx @@ -13,6 +13,7 @@ import { ModalFooter, useDisclosure, } from '@chakra-ui/react'; +import { v4 as uuidv4 } from 'uuid'; import { Table, Thead, Tbody, Tfoot, Tr, Th, Td, TableCaption } from '@chakra-ui/react'; import { predict } from '../../utils/predict'; @@ -34,7 +35,7 @@ function TableComponent({ confusionMatrix, headers }) { {headers.map(x => ( - {x} + {x} ))} @@ -42,7 +43,7 @@ function TableComponent({ confusionMatrix, headers }) { {confusionMatrix.map((x, idx) => { console.log(x, idx); return ( - + {idx === 0 ? ( {headers[idx]} {x.map(y => ( - {y} + {y} ))} ); diff --git a/src/components/Crossvalidator/Crossvalidator.jsx b/src/components/Crossvalidator/Crossvalidator.jsx index 2b5bc14..3a18413 100644 --- a/src/components/Crossvalidator/Crossvalidator.jsx +++ b/src/components/Crossvalidator/Crossvalidator.jsx @@ -1,5 +1,6 @@ import { Box, SimpleGrid, Stack, StackDivider } from '@chakra-ui/react'; import React, { useState, useMemo } from 'react'; +import { v4 as uuidv4 } from 'uuid'; import { mergeChunksWithoutChosen } from '../../utils/cross-valid'; import ConfusionMatrix from '../ConfusionMatrix'; import SmallConfusionMatrix from './SmallConfusionMatrix'; @@ -23,29 +24,31 @@ import TreePrinter from '../TreePrinter'; * @param {Array} props.chunks * @param {Object} props.treeModels - * @returns + * @return */ function CrossValidator({ builder, chunks, treeModels }) { - const [allAccuracy, setAllAccuracy] = useState([]); - const AllAccuracyObject = useMemo(() => Object.values(allAccuracy), [allAccuracy]); + const [allAccuracy, setAllAccuracy] = useState({}); const [selectedTree, setSelectedTree] = useState(null); const [selectedIndex, setSelectedIndex] = useState(0); - const [acc, setAcc] = useState({}); - function updateAccuracy(e, i) { - console.log('Accuracy'); - console.log(e, i); - if (allAccuracy.length != chunks.length) { - //setAllAccuracy([...allAccuracy, e]); + useEffect(() => { + console.log(JSON.parse(JSON.stringify(allAccuracy))); + }, [allAccuracy]); + + function updateAccuracy({ train, test, index }) { + if (allAccuracy[index]?.train === train && allAccuracy[index]?.test === test) { + return; } - // setAllAccuracy(prevState => ({ - // ...prevState, - // [i]: e, - // })); - console.log(allAccuracy); + setAllAccuracy(m => ({ ...m, [index]: { train, test } })); } + const [trainAcc, testAcc] = useMemo(() => { + const items = Object.values(allAccuracy); + const avg = key => items.reduce((acc, x) => acc + x[key], 0) / items.length; + return [avg('train'), avg('test')]; + }, [allAccuracy]); + // useEffect(() => { // function getAccuracy() { // const values = Object.values(AllAccuracyObject); @@ -88,7 +91,7 @@ function CrossValidator({ builder, chunks, treeModels }) { > {treeModels.map((x, i) => (
-

- Training accuracy:{' '} - {allAccuracy?.reduce((partialSum, a) => partialSum + a.training, 0) / allAccuracy.length} -

-

- Test accuracy: {allAccuracy?.reduce((partialSum, a) => partialSum + a.test, 0) / allAccuracy.length} -

+

Training accuracy: {trainAcc}

+

Test accuracy: {testAcc}

Tree {selectedIndex + 1}

@@ -118,7 +116,7 @@ function CrossValidator({ builder, chunks, treeModels }) {
{/*
{treeModels.map((x, i) => ( -

+

Tree {i}{' '} { + setData(mergeChunksWithoutChosen(chunks, index)); + }, []); function clickSelectTree(tree, index) { onSelectedTree(tree, index); } + useEffect(() => { + if (trainAcc === null || testAcc === null) { + return; + } + onGetResults({ train: trainAcc, test: testAcc, index }); + }, [trainAcc, testAcc]); + function getTreningAccuracy(value) { setTrainAcc(value); //onGetResults({ ...acc, training: value }); @@ -169,34 +175,22 @@ function SampleTreeItem({ builder, chunks, item, index, onGetResults, onSelected //onGetResults({ ...acc, test: value }); } - useEffect(() => { - // console.log('usseeffececct', acc); - // if (acc.training != null && acc.test != null) { - // onGetResults(acc); - // } - }, [acc, onGetResults]); - return ( - +

clickSelectTree(item, index)}> Tree {index + 1}

- + {data && ( + + )} options.map(model => ({ ...model, key: model.value })), [options]); const { isLoading } = useLoadingContext(); function handleSelectDecision(value) { @@ -196,7 +197,7 @@ function Navigation({ onPrepareConfig, setHeaders, onCrossValidation }) { placeholder="Select algorithm" onChange={handleSetAlgorithm} value={algorithm} - options={['c45', 'tsp', 'tspw'].map(v => ({ value: v, name: v.toUpperCase() }))} + options={['c45', 'tsp', 'tspw'].map(v => ({ value: v, name: v.toUpperCase(), key: v }))} multiple={true} closeOnSelect={false} /> @@ -216,7 +217,7 @@ function Navigation({ onPrepareConfig, setHeaders, onCrossValidation }) { ( - + {v[0]} ({v[1]}) ));