ml-confusion-matrix
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

confusion-matrix

NPM version build status npm download

Confusion matrix for supervised classification. Compute metrics on your classification like accuracy, sensitivity, specificity. The list of implemented metrics were inspired from the confusion matrix wikipedia page. See API documentation for the list of metrics.

Installation

$ npm install --save ml-confusion-matrix

Usage

Load the library

// CommonJS
const { ConfusionMatrix } = require('ml-confusion-matrix');

// ES6 module syntax
import { ConfusionMatrix } from 'ml-confusion-matrix';

Instanciate from the list of true and predicted labels

Handy if you want a confusion matrix from a cross-validation or from the test data set prediction results.

const trueLabels = [0, 1, 0, 1, 1, 0];
const predictedLabels = [1, 1, 1, 1, 0, 0];

// The order of the arguments are important !!!
const CM2 = ConfusionMatrix.fromLabels(trueLabels, predictedLabels);
console.log(CM2.getAccuracy()); // 0.5

Instanciate from confusion matrix

You can call the constructor directly with the confusion matrix and the labels corresponding to each rows/columns.

const CM1 = new ConfusionMatrix(
  [
    [13, 2],
    [10, 5],
  ],
  ['cat', 'dog'],
);
console.log(CM1.getTruePositiveCount('cat')); // 13

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i ml-confusion-matrix

Weekly Downloads

625

Version

2.0.0

License

MIT

Unpacked Size

79.1 kB

Total Files

15

Last publish

Collaborators

  • stropitek
  • targos
  • lpatiny
  • mljs-bot
  • maasencioh
  • jeffersonh44
  • andcastillo