Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ml-confusion-matrix

mljs5.8kMIT2.0.0TypeScript support: included

Confusion matrix for supervised classification

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

changelog

Changelog

2.0.0 (2023-01-24)

⚠ BREAKING CHANGES

  • replace the default export by a named export

Features

  • use a generatic for the label's type (8e66373)

Miscellaneous Chores

  • do not use default exports (6bd4669)

1.0.0 (2022-12-12)

⚠ BREAKING CHANGES

  • migration to typescript

Features

Miscellaneous Chores

0.4.1 (2022-11-28)

Bug Fixes