Skip to content

Commit

Permalink
feat: accuracy metric for int and category columns
Browse files Browse the repository at this point in the history
  • Loading branch information
neindochoh committed Sep 14, 2023
1 parent 7bc31e1 commit 4af81f1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/widgets/MetricsWidget/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ export const METRICS: Record<string, Metric> = {
},
accuracy: {
signature: {
X: ['bool'],
y: ['bool'],
X: ['bool', 'int', 'Category'],
y: ['bool', 'int', 'Category'],
},
compute: ([actualValues, assignedValues]) => {
const {
truePositives: tp,
trueNegatives: tn,
falsePositives: fp,
falseNegatives: fn,
} = computeConfusion(
actualValues as boolean[],
assignedValues as boolean[]
);
const all = actualValues.length;
let correct = 0;

for (let i = 0; i < actualValues.length; i++) {
const actual = actualValues[i];
const assigned = assignedValues[i];

if (actual === assigned) {
correct++;
}
}

return (tp + tn) / (tp + tn + fp + fn);
return correct / all;
},
},
F1: {
Expand Down

0 comments on commit 4af81f1

Please sign in to comment.