JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1341
  • Score
    100M100P100Q119908F
  • License MIT

Confusion matrix for supervised classification

Package Exports

  • ml-confusion-matrix
  • ml-confusion-matrix/lib-esm/index.js
  • ml-confusion-matrix/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ml-confusion-matrix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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