{"id":19267001,"url":"https://github.com/mljs/confusion-matrix","last_synced_at":"2025-04-21T19:32:31.859Z","repository":{"id":57298964,"uuid":"95661942","full_name":"mljs/confusion-matrix","owner":"mljs","description":"Confusion matrix for supervised classification","archived":false,"fork":false,"pushed_at":"2023-01-24T14:39:17.000Z","size":1330,"stargazers_count":12,"open_issues_count":2,"forks_count":4,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-11-03T02:33:36.443Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mljs.github.io/confusion-matrix/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-28T11:31:08.000Z","updated_at":"2023-11-07T12:45:56.000Z","dependencies_parsed_at":"2023-01-27T21:25:14.419Z","dependency_job_id":null,"html_url":"https://github.com/mljs/confusion-matrix","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fconfusion-matrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fconfusion-matrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fconfusion-matrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fconfusion-matrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/confusion-matrix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223876400,"owners_count":17218387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T20:09:14.314Z","updated_at":"2025-04-21T19:32:31.853Z","avatar_url":"https://github.com/mljs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# confusion-matrix\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![npm download][download-image]][download-url]\n\nConfusion 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](https://en.wikipedia.org/wiki/Confusion_matrix). See [API documentation](https://mljs.github.io/confusion-matrix/) for the list of metrics.\n\n## Installation\n\n`$ npm install --save ml-confusion-matrix`\n\n## Usage\n\n### Load the library\n\n```js\n// CommonJS\nconst { ConfusionMatrix } = require('ml-confusion-matrix');\n\n// ES6 module syntax\nimport { ConfusionMatrix } from 'ml-confusion-matrix';\n```\n\n### Instanciate from the list of true and predicted labels\n\nHandy if you want a confusion matrix from a cross-validation or from the test data set prediction results.\n\n```js\nconst trueLabels = [0, 1, 0, 1, 1, 0];\nconst predictedLabels = [1, 1, 1, 1, 0, 0];\n\n// The order of the arguments are important !!!\nconst CM2 = ConfusionMatrix.fromLabels(trueLabels, predictedLabels);\nconsole.log(CM2.getAccuracy()); // 0.5\n```\n\n### Instanciate from confusion matrix\n\nYou can call the constructor directly with the confusion matrix and the labels corresponding to each rows/columns.\n\n```js\nconst CM1 = new ConfusionMatrix(\n  [\n    [13, 2],\n    [10, 5],\n  ],\n  ['cat', 'dog'],\n);\nconsole.log(CM1.getTruePositiveCount('cat')); // 13\n```\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/ml-confusion-matrix.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-confusion-matrix\n[ci-image]: https://github.com/mljs/confusion-matrix/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/mljs/confusion-matrix/actions?query=workflow%3A%22Node.js+CI%22\n[download-image]: https://img.shields.io/npm/dm/ml-confusion-matrix.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-confusion-matrix\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fconfusion-matrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fconfusion-matrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fconfusion-matrix/lists"}