As the name suggests, this library aims to facilitate the calculations of several metrics using a multi-dimensional confusion matrix.
Provides a set of feature, not only to obtain matrix such as accuracy, precision and f1Score, but also matrix normalization, cloning, numberOfPredictions, etc.
This library was inspired on scikit-learn confusion-matrix written for python. Our goal is to create the same concept for the javascript world.
Run the following command:
npm install confusion-matrix-stats
You just need to create a new Confusion Matrix
instance:
const confusionMatrix = new ConfusionMatrix({
labels: ["Happiness", "Sadness", "Disgust"],
matrix: [[50, 2, 3],
[8, 50 ,5],
[2, 5 ,50]]
});
And then, call the function to obtain the desired metric:
// Calculates the accuracy value for the all matrix.
const accuracy = confusionMatrix.accuracy();
For each metric calculation, is possible to define a different configurations in order to fine tune the calculation formula:
// Calculates the f1Score, only for "sadness" class, using the Macro average method.
const labelAccuracy = confusionMatrix.f1Score({ label: "Sadness", average: AverageMethod.Macro});
You have in here examples for different languages/frameworks.
You can the library documentation here.
Please, give us your feedback here! Also, participate in this project using ricardo1992rocha@gmail.com email contact.
Thank you!