@nlpjs/utils
Advanced tools
Comparing version 4.23.5 to 4.24.0
{ | ||
"name": "@nlpjs/utils", | ||
"version": "4.23.5", | ||
"version": "4.24.0", | ||
"description": "NLP utils", | ||
@@ -30,3 +30,3 @@ "author": { | ||
}, | ||
"gitHead": "9cf31c203950cf995a2d843e523cae6d76390598", | ||
"gitHead": "faa4c3f9b81086e0dd59e225cbf5db4ddef28a19", | ||
"dependencies": { | ||
@@ -33,0 +33,0 @@ "@nlpjs/xtables": "^4.23.5", |
@@ -53,2 +53,3 @@ /* | ||
const current = { | ||
test, | ||
sourceOutput: output, | ||
@@ -106,2 +107,3 @@ expectedIntent: intent, | ||
let correctGoodScore = 0; | ||
const errors = []; | ||
for (let i = 0; i < outputs.length; i += 1) { | ||
@@ -152,4 +154,18 @@ const output = outputs[i]; | ||
current.fn += 1; | ||
// errors.push({ | ||
// type: 'fn', | ||
// expected: output.expectedIntent, | ||
// received: output.topIntent, | ||
// score: output.topScore, | ||
// test: output.test, | ||
// }); | ||
} else if (j === actualIntentPos) { | ||
current.fp += 1; | ||
errors.push({ | ||
type: 'fp', | ||
expected: output.expectedIntent, | ||
received: output.topIntent, | ||
score: output.topScore, | ||
test: output.test, | ||
}); | ||
} else { | ||
@@ -175,2 +191,3 @@ current.tn += 1; | ||
(current.tp + current.tn + current.fp + current.fn); | ||
current.specificity = current.tn / (current.tn + current.fp); | ||
current.precision = current.tp / (current.tp + current.fp); | ||
@@ -185,2 +202,3 @@ current.recall = current.tp / (current.tp + current.fn); | ||
(totals.tp + totals.tn) / (totals.tp + totals.tn + totals.fp + totals.fn); | ||
totals.specificity = totals.tn / (totals.tn + totals.fp); | ||
totals.precision = totals.tp / (totals.tp + totals.fp); | ||
@@ -191,2 +209,3 @@ totals.recall = totals.tp / (totals.tp + totals.fn); | ||
(totals.precision + totals.recall); | ||
analysis.errors = errors; | ||
return analysis; | ||
@@ -206,4 +225,5 @@ } | ||
'Accuracy', | ||
'Specificity / TN rate', | ||
'Precision', | ||
'Recall', | ||
'Recall / Sensitivity / TP rate', | ||
'F1-Score', | ||
@@ -216,3 +236,3 @@ ]; | ||
for (let i = 0; i < 8; i += 1) { | ||
for (let i = 0; i < titles.length; i += 1) { | ||
const pos = XTableUtils.coord2excel({ | ||
@@ -244,5 +264,6 @@ column: intents.length + i + 2, | ||
this.writeAt(sheet, intents.length + 6, i + 1, intents[i].accuracy); | ||
this.writeAt(sheet, intents.length + 7, i + 1, intents[i].precision); | ||
this.writeAt(sheet, intents.length + 8, i + 1, intents[i].recall); | ||
this.writeAt(sheet, intents.length + 9, i + 1, intents[i].f1Score); | ||
this.writeAt(sheet, intents.length + 7, i + 1, intents[i].specificity); | ||
this.writeAt(sheet, intents.length + 8, i + 1, intents[i].precision); | ||
this.writeAt(sheet, intents.length + 9, i + 1, intents[i].recall); | ||
this.writeAt(sheet, intents.length + 10, i + 1, intents[i].f1Score); | ||
const row = matrix[i]; | ||
@@ -276,10 +297,12 @@ for (let j = 0; j < intents.length; j += 1) { | ||
const sheet = workbook.addWorksheet('Analysis'); | ||
sheet.getColumn(2).width = 20; | ||
sheet.getColumn(2).width = 30; | ||
sheet.getColumn(5).width = 20; | ||
this.writeAt(sheet, 1, 3, 'Name'); | ||
this.writeAt(sheet, 2, 3, analysis.corpus.name); | ||
this.writeAt(sheet, 1, 4, 'Language'); | ||
this.writeAt(sheet, 2, 4, analysis.corpus.locale); | ||
this.writeAt(sheet, 1, 5, 'Total Tests'); | ||
this.writeAt(sheet, 2, 5, analysis.outputs.length); | ||
this.writeAt(sheet, 1, 2, 'Name'); | ||
this.writeAt(sheet, 2, 2, analysis.corpus.name); | ||
this.writeAt(sheet, 1, 3, 'Language'); | ||
this.writeAt(sheet, 2, 3, analysis.corpus.locale); | ||
this.writeAt(sheet, 1, 4, 'Total Tests'); | ||
this.writeAt(sheet, 2, 4, analysis.outputs.length); | ||
this.writeAt(sheet, 1, 5, 'Threshold'); | ||
this.writeAt(sheet, 2, 5, this.threshold); | ||
this.writeAt(sheet, 1, 6, 'Correct'); | ||
@@ -303,8 +326,10 @@ this.writeAt(sheet, 2, 6, analysis.correct); | ||
this.writeAt(sheet, 2, 14, analysis.confusionMatrix.totals.accuracy); | ||
this.writeAt(sheet, 1, 15, 'Precision'); | ||
this.writeAt(sheet, 2, 15, analysis.confusionMatrix.totals.precision); | ||
this.writeAt(sheet, 1, 16, 'Recall'); | ||
this.writeAt(sheet, 2, 16, analysis.confusionMatrix.totals.recall); | ||
this.writeAt(sheet, 1, 17, 'F1-Score'); | ||
this.writeAt(sheet, 2, 17, analysis.confusionMatrix.totals.f1Score); | ||
this.writeAt(sheet, 1, 15, 'Specificity'); | ||
this.writeAt(sheet, 2, 15, analysis.confusionMatrix.totals.specificity); | ||
this.writeAt(sheet, 1, 16, 'Precision'); | ||
this.writeAt(sheet, 2, 16, analysis.confusionMatrix.totals.precision); | ||
this.writeAt(sheet, 1, 17, 'Recall'); | ||
this.writeAt(sheet, 2, 17, analysis.confusionMatrix.totals.recall); | ||
this.writeAt(sheet, 1, 18, 'F1-Score'); | ||
this.writeAt(sheet, 2, 18, analysis.confusionMatrix.totals.f1Score); | ||
@@ -327,2 +352,24 @@ this.writeAt(sheet, 5, 20, '0..10'); | ||
} | ||
if (analysis.errors) { | ||
const sheetWithWErrors = workbook.addWorksheet('Errors'); | ||
sheetWithWErrors.getColumn(2).width = 30; | ||
sheetWithWErrors.getColumn(3).width = 30; | ||
sheetWithWErrors.getColumn(5).width = 60; | ||
this.writeAt(sheetWithWErrors, 0, 0, 'Error type'); | ||
this.writeAt(sheetWithWErrors, 1, 0, 'Expected'); | ||
this.writeAt(sheetWithWErrors, 2, 0, 'Received'); | ||
this.writeAt(sheetWithWErrors, 3, 0, 'Score'); | ||
this.writeAt(sheetWithWErrors, 4, 0, 'Test'); | ||
for (let i = 1; i <= analysis.errors.length; i += 1) { | ||
const error = analysis.errors[i - 1]; | ||
this.writeAt(sheetWithWErrors, 0, i, error.type); | ||
this.writeAt(sheetWithWErrors, 1, i, error.expected); | ||
this.writeAt(sheetWithWErrors, 2, i, error.received); | ||
this.writeAt(sheetWithWErrors, 3, i, error.score); | ||
this.writeAt(sheetWithWErrors, 4, i, error.test); | ||
} | ||
} | ||
} | ||
@@ -329,0 +376,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60736
1637