{"id":34059789,"url":"https://github.com/arvkevi/disarray","last_synced_at":"2026-04-07T06:32:59.684Z","repository":{"id":51280525,"uuid":"213269191","full_name":"arvkevi/disarray","owner":"arvkevi","description":"Confusion matrix metrics directly from your pandas DataFrame","archived":false,"fork":false,"pushed_at":"2021-05-18T00:20:11.000Z","size":12983,"stargazers_count":35,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-11-27T17:47:16.956Z","etag":null,"topics":["confusion-matrix","data-analysis","data-science","dataframe","machine-learning","pandas","performance-metrics"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/arvkevi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-07T01:01:05.000Z","updated_at":"2025-05-27T07:04:02.000Z","dependencies_parsed_at":"2022-09-07T12:11:39.515Z","dependency_job_id":null,"html_url":"https://github.com/arvkevi/disarray","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/arvkevi/disarray","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvkevi%2Fdisarray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvkevi%2Fdisarray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvkevi%2Fdisarray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvkevi%2Fdisarray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arvkevi","download_url":"https://codeload.github.com/arvkevi/disarray/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arvkevi%2Fdisarray/sbom","scorecard":{"id":210431,"data":{"date":"2025-08-11","repo":{"name":"github.com/arvkevi/disarray","commit":"a6ec5d5bfd08601eca0836fd3781b759746b0caa"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/python-unittest.yml:1","Warn: no topLevel permission defined: .github/workflows/pythonpublish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/10 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-unittest.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/arvkevi/disarray/python-unittest.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-unittest.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/arvkevi/disarray/python-unittest.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/python-unittest.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/arvkevi/disarray/python-unittest.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pythonpublish.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/arvkevi/disarray/pythonpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pythonpublish.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/arvkevi/disarray/pythonpublish.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/python-unittest.yml:18","Warn: pipCommand not pinned by hash: .github/workflows/python-unittest.yml:19","Warn: pipCommand not pinned by hash: .github/workflows/python-unittest.yml:20","Warn: pipCommand not pinned by hash: .github/workflows/python-unittest.yml:26","Warn: pipCommand not pinned by hash: .github/workflows/pythonpublish.yml:18","Warn: pipCommand not pinned by hash: .github/workflows/pythonpublish.yml:19","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   6 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":2,"reason":"8 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2020-107 / GHSA-jjw5-xxj6-pcv5","Warn: Project is vulnerable to: PYSEC-2024-110 / GHSA-jw8x-6495-233v","Warn: Project is vulnerable to: PYSEC-2020-108","Warn: Project is vulnerable to: PYSEC-2021-856 / GHSA-5545-2q6w-2gh6","Warn: Project is vulnerable to: GHSA-6p56-wp2h-9hxr","Warn: Project is vulnerable to: PYSEC-2021-857 / GHSA-f7c7-j99h-c22f","Warn: Project is vulnerable to: GHSA-fpfv-jqm9-f5jm","Warn: Project is vulnerable to: PYSEC-2020-73"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 24 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T00:40:14.607Z","repository_id":51280525,"created_at":"2025-08-17T00:40:14.607Z","updated_at":"2025-08-17T00:40:14.607Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31503383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["confusion-matrix","data-analysis","data-science","dataframe","machine-learning","pandas","performance-metrics"],"created_at":"2025-12-14T04:01:47.678Z","updated_at":"2026-04-07T06:32:59.678Z","avatar_url":"https://github.com/arvkevi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# disarray\n[![Downloads](https://pepy.tech/badge/disarray)](https://pepy.tech/project/disarray)\n[![Downloads](https://pepy.tech/badge/disarray/month)](https://pepy.tech/project/disarray/month)\n[![Build Status](https://travis-ci.com/arvkevi/disarray.svg?branch=master)](https://travis-ci.com/arvkevi/disarray)\n[![codecov](https://codecov.io/gh/arvkevi/disarray/branch/master/graph/badge.svg)](https://codecov.io/gh/arvkevi/disarray)\n\n`disarray` calculates metrics derived from a confusion matrix and makes them directly accessible from a pandas DataFrame.\n\n![disarray demo](demo/disarray_demo.gif)\n\nIf you are already using [`pandas`](https://pandas.pydata.org/), then `disarray` is easy to use, simply import `disarray`:\n ```python\nimport pandas as pd\n\n# dtype=int is important for Windows users\ndf = pd.DataFrame([[18, 1], [0, 1]], dtype=int)\n\nimport disarray\n\ndf.da.sensitivity\n0    0.947368\n1    1.000000\ndtype: float64\n```\n\n## Table of contents\n- [Installation](#installation)\n- [Usage](#usage)\n    * [binary classification](#binary-classification)\n    * [class counts](#class-counts)\n    * [export metrics](#export-metrics)\n    * [multi-class classification](#multi-class-classification)\n    * [supported metrics](#supported-metrics)\n- [Why disarray](#why-disarray?)\n- [Contributing](#contributing)\n\n## Installation\n**Install using pip**\n```bash\n$ pip install disarray\n```\n\n**Clone from GitHub**\n```bash\n$ git clone https://github.com/arvkevi/disarray.git\n$ python setup.py install\n```\n\n## Usage\nThe `disarray` package is intended to be used similar to a `pandas` attribute or method. `disarray` is registered as \na `pandas` extension under `da`. For a DataFrame named `df`, access the library using `df.da.`.\n\n\n### Binary Classification\nTo understand the input and usage for `disarray`, build an example confusion matrix for a **binary classification**\n problem from scratch with `scikit-learn`.   \n(You can install the packages you need to run the demo with: `pip install -r requirements.demo.txt`)\n\n```python\nfrom sklearn import svm, datasets\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix\n# Generate a random binary classification dataset\nX, y = datasets.make_classification(n_classes=2, random_state=42)\nX_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)\n# fit and predict an SVM\nclassifier = svm.SVC(kernel='linear', C=0.01)\ny_pred = classifier.fit(X_train, y_train).predict(X_test)\n\ncm = confusion_matrix(y_test, y_pred)\nprint(cm)\n[[13  2]\n [ 0 10]]\n```\n\nUsing `disarray` is as easy as importing it and instantiating a DataFrame object from a **square** array of **positive** integers.\n\n```python\nimport disarray\nimport pandas as pd\n\n# dtype=int is important for Windows users\ndf = pd.DataFrame(cm, dtype=int)\n# access metrics for each class by index\nprint(df.da.precision[1])\n0.83\n```\n\n### Class Counts\n`disarray` stores per-class counts of true positives, false positives, false negatives, and true negatives. Each of these are stored as capitalized abbreviations, `TP`, `FP`, `FN`, and `TN`.\n\n```python\ndf.da.TP\n```\n```python\n0    13\n1    10\ndtype: int64\n```\n\n### Export Metrics\nUse `df.da.export_metrics()` to store and/or visualize many common performance metrics in a new `pandas` DataFrame \nobject. Use the `metrics_to_include=` argument to pass a list of metrics defined in `disarray/metrics.py` (default is \nto use `__all_metrics__`).\n\n```python\ndf.da.export_metrics(metrics_to_include=['precision', 'recall', 'f1'])\n```\n|           |        0 |        1 |   micro-average |\n|-----------|----------|----------|-----------------|\n| precision | 1.0      | 0.833333 |            0.92 |\n| recall    | 0.866667 | 1.0      |            0.92 |\n| f1        | 0.928571 | 0.909091 |            0.92 |\n\n\n\n### Multi-Class Classification\n`disarray` works with multi-class classification confusion matrices also. Try it out on the iris dataset. Notice, the\n DataFrame is instantiated with an `index` and `columns` here, but it is not required.\n\n```python\n# load the iris dataset\niris = datasets.load_iris()\nX = iris.data\ny = iris.target\nclass_names = iris.target_names\n# split the training and testing data\nX_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)\n# train and fit a SVM\nclassifier = svm.SVC(kernel='linear', C=0.01)\ny_pred = classifier.fit(X_train, y_train).predict(X_test)\ncm = confusion_matrix(y_test, y_pred)\n\n# Instantiate the confusion matrix DataFrame with index and columns\n# dtype=int is important for Windows users\ndf = pd.DataFrame(cm, index=class_names, columns=class_names, dtype=int)\nprint(df)\n```\n|            |   setosa |   versicolor |   virginica |\n|------------|----------|--------------|-------------|\n| setosa     |       13 |            0 |           0 |\n| versicolor |        0 |           10 |           6 |\n| virginica  |        0 |            0 |           9 |\n\n`disarray` can provide per-class metrics:\n\n```python\ndf.da.sensitivity\n```\n```python\nsetosa        1.000\nversicolor    0.625\nvirginica     1.000\ndtype: float64\n```\nIn a familiar fashion, one of the classes can be accessed with bracket indexing.\n\n```python\ndf.da.sensitivity['setosa']\n```\n```python\n1.0\n```\nCurrently, a [micro-average](https://datascience.stackexchange.com/a/24051/16855) is supported for both binary and\n multi-class classification confusion matrices. (Although it only makes sense in the multi-class case).\n```python\ndf.da.micro_sensitivity\n```\n```python\n0.8421052631578947\n```\nFinally, a DataFrame can be exported with selected metrics.\n```python\ndf.da.export_metrics(metrics_to_include=['sensitivity', 'specificity', 'f1'])\n```\n\n|             |   setosa |   versicolor |   virginica |   micro-average |\n|-------------|----------|--------------|-------------|-----------------|\n| sensitivity |      1.0 |     0.625    |    1.0      |        0.842105 |\n| specificity |      1.0 |     1.0      |    0.793103 |        0.921053 |\n| f1          |      1.0 |     0.769231 |    0.75     |        0.842105 |\n\n### Supported Metrics\n```python\n'accuracy',\n'f1',\n'false_discovery_rate',\n'false_negative_rate',\n'false_positive_rate',\n'negative_predictive_value',\n'positive_predictive_value',\n'precision',\n'recall',\n'sensitivity',\n'specificity',\n'true_negative_rate',\n'true_positive_rate',\n```\nAs well as micro-averages for each of these, accessible via `df.da.micro_recall`, for example.\n\n## Why disarray?\n\nWorking with a [confusion matrix](https://en.wikipedia.org/wiki/Confusion_matrix) is common in data science projects. It is useful to have performance metrics available directly from [pandas](https://pandas.pydata.org/) DataFrames. \n \nSince `pandas` version `0.23.0`, users can easily\n[register custom accessors](https://pandas.pydata.org/pandas-docs/stable/development/extending.html#extending-pandas),\n which is how `disarray` is implemented.\n\n## Contributing\n\nContributions are welcome, please refer to [CONTRIBUTING](https://github.com/arvkevi/disarray/blob/master/CONTRIBUTING.md) \nto learn more about how to contribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farvkevi%2Fdisarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farvkevi%2Fdisarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farvkevi%2Fdisarray/lists"}