text: !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i=t();for(var s in i)("object"==typeof exports?exports:e)[s]=i[s]}}(self,(function(){return(()=>{"use strict";var e={975:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AverageMethod=t.ConfusionMatrix=void 0;class i{constructor(e){this.labels=new Array,this.matrix=new Array,this.normalizations=new Array,this.history=new Array,this.historyPointer=-1,e&&(this.labels=this.deepCopy(e.labels),this.matrix=this.deepCopy(e.matrix)),this.validate()}setConfusionMatrix(e,t=!0){return e&&(this.labels=this.deepCopy(e.labels),this.matrix=this.deepCopy(e.matrix),t&&this.addToHistory()),this.validate(),this}normalize(e=0,t=1,s){if(e>=t)throw new Error("Min value cannot be equal or greater than max value.");this.validate();const r=this.getMinAndMax();if(r){this.normalizations.push(new i(this));const a=r.min,l=r.max;for(let i=0;i<this.matrix.length;i++)for(let r=0;r<this.matrix[i].length;r++){const o=this.matrix[i][r];this.matrix[i][r]=(o-a)/(l-a)*(t-e)+e,null!=s&&(this.matrix[i][r]=+this.matrix[i][r].toFixed(s))}this.addToHistory()}return this}accuracy(e={average:s.Weighted}){return this.validate(),e.label&&e.label.length>0?this.labelAccuracy(e.label):this.matrixAccuracy(e.average)}labelAccuracy(e){this.validate();const{truePositive:t,trueNegative:i,falsePositive:s,falseNegative:r}=this.getConfusionMatrixClasses(e);return(t+i)/(t+i+s+r)||0}matrixAccuracy(e=s.Weighted){switch(this.validate(),e){case s.Micro:return this.microAccuracy();case s.Macro:return this.macroAccuracy();case s.Weighted:return this.weightedAccuracy()}}microAccuracy(){const{truePositive:e,trueNegative:t,falsePositive:i,falseNegative:s}=this.getSumConfusionMatrixClasses();return(e+t)/(e+t+i+s)||0}macroAccuracy(){let e=0;return this.labels.forEach((t=>e+=this.labelAccuracy(t))),e/this.labels.length||0}weightedAccuracy(){const e=this.getLabelsPredictionsSum(),t=this.getNumberOfPredictions();let i=0;return this.labels.forEach(((t,s)=>i+=this.labelAccuracy(t)*e[s])),i/t||0}missClassificationRate(e={average:s.Weighted}){return this.validate(),(null==e?void 0:e.label)&&(null==e?void 0:e.label.length)>0?this.labelMissClassificationRate(e.label):this.matrixMissClassificationRate(null==e?void 0:e.average)}labelMissClassificationRate(e){this.validate();const{truePositive:t,trueNegative:i,falsePositive:s,falseNegative:r}=this.getConfusionMatrixClasses(e);return(s+r)/(t+i+s+r)||0}matrixMissClassificationRate(e=s.Weighted){switch(this.validate(),e){case s.Micro:return this.microMissClassificationRate();case s.Macro:return this.macroMissClassificationRate();case s.Weighted:return this.weightedMissClassificationRate()}}microMissClassificationRate(){const{truePositive:e,trueNegative:t,falsePositive:i,falseNegative:s}=this.getSumConfusionMatrixClasses();return(i+s)/(e+t+i+s)||0}macroMissClassificationRate(){let e=0;return this.labels.forEach((t=>e+=this.labelMissClassificationRate(t))),e/this.labels.length||0}weightedMissClassificationRate(){const e=this.getLabelsPredictionsSum(),t=this.getNumberOfPredictions();let i=0;return this.labels.forEach(((t,s)=>i+=this.labelMissClassificationRate(t)*e[s])),i/t||0}precision(e={average:s.Weighted}){return this.validate(),(null==e?void 0:e.label)&&(null==e?void 0:e.label.length)>0?this.labelPrecision(e.label):this.matrixPrecision(null==e?void 0:e.average)}labelPrecision(e){this.validate();const{truePositive:t,falsePositive:i}=this.getConfusionMatrixClasses(e);return t/(t+i)||0}matrixPrecision(e=s.Weighted){switch(this.validate(),e){case s.Micro:return this.microPrecision();case s.Macro:return this.macroPrecision();case s.Weighted:return this.weightedPrecision()}}microPrecision(){const{truePositive:e,falsePositive:t}=this.getSumConfusionMatrixClasses();return e/(e+t)||0}macroPrecision(){let e=0;return this.labels.forEach((t=>e+=this.labelPrecision(t))),e/this.labels.length||0}weightedPrecision(){const e=this.getLabelsPredictionsSum(),t=this.getNumberOfPredictions();let i=0;return this.labels.forEach(((t,s)=>i+=this.labelPrecision(t)*e[s])),i/t||0}recall(e={average:s.Weighted}){return this.validate(),(null==e?void 0:e.label)&&(null==e?void 0:e.label.length)>0?this.labelRecall(e.label):this.matrixRecall(null==e?void 0:e.average)}labelRecall(e){this.validate();const{truePositive:t,falseNegative:i}=this.getConfusionMatrixClasses(e);return t/(t+i)||0}matrixRecall(e=s.Weighted){switch(this.validate(),e){case s.Micro:return this.microRecall();case s.Macro:return this.macroRecall();case s.Weighted:return this.weightedRecall()}}microRecall(){const{truePositive:e,falseNegative:t}=this.getSumConfusionMatrixClasses();return e/(e+t)||0}macroRecall(){let e=0;return this.labels.forEach((t=>e+=this.labelRecall(t))),e/this.labels.length||0}weightedRecall(){const e=this.getLabelsPredictionsSum(),t=this.getNumberOfPredictions();let i=0;return this.labels.forEach(((t,s)=>i+=this.labelRecall(t)*e[s])),i/t||0}specificity(e={average:s.Weighted}){return this.validate(),(null==e?void 0:e.label)&&(null==e?void 0:e.label.length)>0?this.labelSpecificity(e.label):this.matrixSpecificity(null==e?void 0:e.average)}matrixSpecificity(e=s.Weighted){switch(this.validate(),e){case s.Micro:return this.microSpecificity();case s.Macro:return this.macroSpecificity();case s.Weighted:return this.weightedSpecificity()}}microSpecificity(){const{trueNegative:e,falsePositive:t}=this.getSumConfusionMatrixClasses();return e/(e+t)||0}macroSpecificity(){let e=0;return this.labels.forEach((t=>e+=this.labelSpecificity(t))),e/this.labels.length||0}weightedSpecificity(){const e=this.getLabelsPredictionsSum(),t=this.getNumberOfPredictions();let i=0;return this.labels.forEach(((t,s)=>i+=this.labelSpecificity(t)*e[s])),i/t||0}labelSpecificity(e){this.validate();const{trueNegative:t,falsePositive:i}=this.getConfusionMatrixClasses(e);return t/(t+i)||0}f1Score(e){return this.validate(),(null==e?void 0:e.label)&&(null==e?void 0:e.label.length)>0?this.labelF1Score(e.label):this.matrixF1Score(null==e?void 0:e.average)}matrixF1Score(e=s.Weighted){switch(this.validate(),e){case s.Micro:return this.microF1Score();case s.Macro:return this.macroF1Score();case s.Weighted:return this.weightedF1Score()}}labelF1Score(e){this.validate();const t=this.precision({label:e}),i=this.recall({label:e});return t*i/(t+i)*2||0}microF1Score(){const e=this.microPrecision(),t=this.microRecall();return this.applyF1ScoreFormula(e,t)}macroF1Score(){let e=0;return this.labels.forEach((t=>e+=this.labelF1Score(t))),e/this.labels.length||0}weightedF1Score(){const e=this.getLabelsPredictionsSum(),t=this.getNumberOfPredictions();let i=0;return this.labels.forEach(((t,s)=>i+=this.labelF1Score(t)*e[s])),i/t||0}getAllMatrixClasses(){this.validate();const e=new Array;return this.labels.forEach((t=>e.push({label:t,confusionMatrixClasses:this.getConfusionMatrixClasses(t)}))),e}getSumConfusionMatrixClasses(){const e={truePositive:0,trueNegative:0,falsePositive:0,falseNegative:0};return this.getAllMatrixClasses().forEach((t=>{e.truePositive+=t.confusionMatrixClasses.truePositive,e.trueNegative+=t.confusionMatrixClasses.trueNegative,e.falsePositive+=t.confusionMatrixClasses.falsePositive,e.falseNegative+=t.confusionMatrixClasses.falseNegative})),e}getConfusionMatrixClasses(e){if(this.validate(),!e)throw new Error("A valid label should be passed.");const t=this.labels.findIndex((t=>t===e));if(-1==t)throw new Error("The label does not exists in the matrix.");const i=this.getNumberOfPredictions(),s=this.matrix[t][t],r=this.matrix[t].reduce(((e,t)=>e+t))-s;let a=0;for(let e=0;e<this.matrix.length;e++)a+=this.matrix[e][t];return a-=s,{truePositive:s,trueNegative:i-s-r-a,falsePositive:r,falseNegative:a}}revertNormalization(){const e=this.normalizations.pop();return e?(this.setConfusionMatrix(e),this.addToHistory(),e):null}clone(){const e=new i({labels:this.labels,matrix:this.matrix});return e.normalizations=this.deepCopy(this.normalizations),e}getMinAndMax(){let e=this.matrix[0][0],t=this.matrix[0][0];if(!e||!t)return null;for(let i of this.matrix)for(let s of i)t=t<s?s:t,e=e>s?s:e;return{min:e,max:t}}revertAllNormalizations(){return this.normalizations&&this.normalizations.length>0?this.setConfusionMatrix(this.normalizations[0]):this}getNumberOfPredictions(e){const t=this.getLabelsPredictionsSum();return e&&e.length>0?t[this.labels.findIndex((t=>t===e))]:t.reduce(((e,t)=>e+t))}getLabelsPredictionsSum(){let e=new Array(this.labels.length).fill(0,0,this.labels.length);return this.matrix.forEach((t=>t.forEach(((t,i)=>{e[i]+=t})))),e}validate(){if(this.labels.length!==this.matrix.length)throw new Error("The labels length should be equals to the matrix columns length.");for(let e=0;e<this.labels.length-1;e++)for(let t=e+1;t<this.labels.length;t++)if(this.labels[e]===this.labels[t])throw new Error(`The label ${this.labels[e]} appears more than once in the labels array.`);return this.matrix.forEach((e=>{if(e.length!==this.matrix.length)throw new Error("The confusion matrix does not have the columns/rows length.")})),this}transpose(){return this.matrix=this.matrix[0].map(((e,t)=>this.matrix.map((e=>e[t])))),this.addToHistory(),this}isUndoAvailable(){return!(-1===this.historyPointer)}undo(){if(this.isUndoAvailable())return this.historyPointer--,this.setConfusionMatrix(this.history[this.historyPointer],!1),this}isRedoAvailable(){return!(this.historyPointer===this.history.length-1)}redo(){if(this.isRedoAvailable())return this.historyPointer++,this.setConfusionMatrix(this.history[this.historyPointer],!1),this}deepCopy(e){return JSON.parse(JSON.stringify(e))}applyF1ScoreFormula(e,t){return e*t/(e+t)*2||0}addToHistory(){this.history.push(this.clone()),-1===this.historyPointer?this.historyPointer=0:this.historyPointer++}}var s;t.ConfusionMatrix=i,function(e){e[e.Micro=0]="Micro",e[e.Macro=1]="Macro",e[e.Weighted=2]="Weighted"}(s=t.AverageMethod||(t.AverageMethod={}))},590:function(e,t,i){var s=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[i]}})}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),r=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||s(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0}),r(i(975),t)}},t={};return function i(s){var r=t[s];if(void 0!==r)return r.exports;var a=t[s]={exports:{}};return e[s].call(a.exports,a,a.exports,i),a.exports}(590)})()}));