{"id":13655988,"url":"https://github.com/sepandhaghighi/pycm","last_synced_at":"2025-05-13T20:19:25.545Z","repository":{"id":28478555,"uuid":"118506495","full_name":"sepandhaghighi/pycm","owner":"sepandhaghighi","description":"Multi-class confusion matrix library in Python","archived":false,"fork":false,"pushed_at":"2025-05-13T07:22:19.000Z","size":12081,"stargazers_count":1475,"open_issues_count":18,"forks_count":126,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-05-13T08:32:31.853Z","etag":null,"topics":["accuracy","ai","artificial-intelligence","classification","confusion-matrix","data","data-analysis","data-mining","data-science","deep-learning","deeplearning","evaluation","machine-learning","mathematics","matrix","ml","multiclass-classification","neural-network","statistical-analysis","statistics"],"latest_commit_sha":null,"homepage":"http://pycm.io","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/sepandhaghighi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"custom":"https://www.pycm.io/donate.html"}},"created_at":"2018-01-22T19:46:54.000Z","updated_at":"2025-05-06T16:03:20.000Z","dependencies_parsed_at":"2023-12-07T07:26:25.768Z","dependency_job_id":"0bd82b13-9c3b-4d3d-9f1e-48085fdf89b0","html_url":"https://github.com/sepandhaghighi/pycm","commit_stats":{"total_commits":2791,"total_committers":18,"mean_commits":"155.05555555555554","dds":"0.22644213543532787","last_synced_commit":"a163c07fb23fd5384f4a6049afa16241954f6545"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sepandhaghighi%2Fpycm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sepandhaghighi%2Fpycm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sepandhaghighi%2Fpycm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sepandhaghighi%2Fpycm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sepandhaghighi","download_url":"https://codeload.github.com/sepandhaghighi/pycm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253907475,"owners_count":21982437,"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":["accuracy","ai","artificial-intelligence","classification","confusion-matrix","data","data-analysis","data-mining","data-science","deep-learning","deeplearning","evaluation","machine-learning","mathematics","matrix","ml","multiclass-classification","neural-network","statistical-analysis","statistics"],"created_at":"2024-08-02T04:00:44.976Z","updated_at":"2025-05-13T20:19:25.512Z","avatar_url":"https://github.com/sepandhaghighi.png","language":"Python","funding_links":["https://www.pycm.io/donate.html"],"categories":["Python","Machine Learning Framework","其他_机器学习与深度学习","Uncategorized","Exploration"],"sub_categories":["Model Interpretation","General-Purpose Machine Learning","Uncategorized"],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/logo.png\" width=\"550\"\u003e\n\u003ch1\u003ePyCM: Python Confusion Matrix\u003c/h1\u003e\n\u003cbr/\u003e\n\u003ca href=\"https://www.python.org/\"\u003e\u003cimg src=\"https://img.shields.io/badge/built%20with-Python3-green.svg\" alt=\"built with Python3\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sepandhaghighi/pycm\"\u003e\u003cimg alt=\"GitHub repo size\" src=\"https://img.shields.io/github/repo-size/sepandhaghighi/pycm\"\u003e\u003c/a\u003e\n\u003ca href=\"/Document\"\u003e\u003cimg src=\"https://img.shields.io/badge/doc-latest-orange.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/sepandhaghighi/pycm\"\u003e\u003cimg src=\"https://codecov.io/gh/sepandhaghighi/pycm/branch/master/graph/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://badge.fury.io/py/pycm\"\u003e\u003cimg src=\"https://badge.fury.io/py/pycm.svg\" alt=\"PyPI version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://anaconda.org/sepandhaghighi/pycm\"\u003e\u003cimg src=\"https://anaconda.org/sepandhaghighi/pycm/badges/version.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://colab.research.google.com/github/sepandhaghighi/pycm/blob/master\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Document\"\u003e\u003c/a\u003e\n\u003ca href=\"https://discord.com/invite/zqpU2b3J3f\"\u003e\u003cimg src=\"https://img.shields.io/discord/901883546162065408.svg\" alt=\"Discord Channel\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## Overview\n\n\u003cp align=\"justify\"\u003e\t\nPyCM is a multi-class confusion matrix library written in Python that supports both input data vectors and direct matrix, and a proper tool for post-classification model evaluation that supports most classes and overall statistics parameters.\nPyCM is the swiss-army knife of confusion matrices, targeted mainly at data scientists that need a broad array of metrics for predictive models and accurate evaluation of a large variety of classifiers.\n\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/block_diagram.jpg\" width=\"700\"\u003e\n\u003cp\u003eFig1. ConfusionMatrix Block Diagram\u003c/p\u003e\n\u003c/div\u003e\n\n\u003ctable\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003eOpen Hub\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://www.openhub.net/p/pycm\"\u003e\u003cimg src=\"https://www.openhub.net/p/pycm/widgets/project_thin_badge.gif\"\u003e\u003c/a\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003ePyPI Counter\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://pepy.tech/projects/pycm\"\u003e\u003cimg src=\"https://static.pepy.tech/badge/pycm\" alt=\"PyPI Downloads\"\u003e\u003c/a\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003eGithub Stars\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/sepandhaghighi/pycm\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/sepandhaghighi/pycm.svg?style=social\u0026label=Stars\"\u003e\u003c/a\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n\n\n\n\u003ctable\u003e\n\t\u003ctr\u003e \n\t\t\u003ctd align=\"center\"\u003eBranch\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003emaster\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003edev\u003c/td\u003e\n\t\u003c/tr\u003e\n    \u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003eCI\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003cimg src=\"https://github.com/sepandhaghighi/pycm/actions/workflows/test.yml/badge.svg?branch=master\"\u003e\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003cimg src=\"https://github.com/sepandhaghighi/pycm/actions/workflows/test.yml/badge.svg?branch=dev\"\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n\n\n\u003ctable\u003e\n\t\u003ctr\u003e \n\t\t\u003ctd align=\"center\"\u003eCode Quality\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca class=\"badge-align\" href=\"https://www.codacy.com/app/sepand-haghighi/pycm?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=sepandhaghighi/pycm\u0026amp;utm_campaign=Badge_Grade\"\u003e\u003cimg src=\"https://api.codacy.com/project/badge/Grade/5d9463998a0040d09afc2b80c389365c\"/\u003e\u003c/a\u003e\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://www.codefactor.io/repository/github/sepandhaghighi/pycm/overview/dev\"\u003e\u003cimg src=\"https://www.codefactor.io/repository/github/sepandhaghighi/pycm/badge/dev\" alt=\"CodeFactor\" /\u003e\u003c/a\u003e\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://codebeat.co/projects/github-com-sepandhaghighi-pycm-dev\"\u003e\u003cimg alt=\"codebeat badge\" src=\"https://codebeat.co/badges/f6642af1-c343-48c2-bd3e-eee802facf39\" /\u003e\u003c/a\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n\n## Installation\n\n⚠️  PyCM 3.9 is the last version to support **Python 3.5**\n\n⚠️  PyCM 2.4 is the last version to support **Python 2.7** \u0026 **Python 3.4**\n\n⚠️  Plotting capability requires **Matplotlib (\u003e= 3.0.0)** or **Seaborn (\u003e= 0.9.1)**\n\n### PyPI\n\n- Check [Python Packaging User Guide](https://packaging.python.org/installing/)\n- Run `pip install pycm==4.3`\n\n### Source code\n- Download [Version 4.3](https://github.com/sepandhaghighi/pycm/archive/v4.3.zip) or [Latest Source](https://github.com/sepandhaghighi/pycm/archive/dev.zip)\n- Run `pip install .`\n\n### Conda\n\n- Check [Conda Managing Package](https://conda.io/)\n- Update Conda using `conda update conda`\n- Run `conda install -c sepandhaghighi pycm`\n\n### MATLAB\n\n- Download and install [MATLAB](https://www.mathworks.com/products/matlab.html) (\u003e=8.5, 64/32 bit)\n- Download and install [Python3.x](https://www.python.org/downloads/) (\u003e=3.6, 64/32 bit)\n\t- [x] Select `Add to PATH` option\n\t- [x] Select `Install pip` option\n- Run `pip install pycm`\n- Configure Python interpreter\n\n```matlab\n\u003e\u003e pyversion PYTHON_EXECUTABLE_FULL_PATH\n```\n\n- Visit [MATLAB Examples](https://github.com/sepandhaghighi/pycm/tree/master/MATLAB)\n\n## Usage\n\n### From vector\n\n```pycon\n\u003e\u003e\u003e from pycm import *\n\u003e\u003e\u003e y_actu = [2, 0, 2, 2, 0, 1, 1, 2, 2, 0, 1, 2]\n\u003e\u003e\u003e y_pred = [0, 0, 2, 1, 0, 2, 1, 0, 2, 0, 2, 2]\n\u003e\u003e\u003e cm = ConfusionMatrix(actual_vector=y_actu, predict_vector=y_pred)\n\u003e\u003e\u003e cm.classes\n[0, 1, 2]\n\u003e\u003e\u003e cm.table\n{0: {0: 3, 1: 0, 2: 0}, 1: {0: 0, 1: 1, 2: 2}, 2: {0: 2, 1: 1, 2: 3}}\n\u003e\u003e\u003e cm.print_matrix()\nPredict 0       1       2       \nActual\n0       3       0       0       \n\n1       0       1       2       \n\n2       2       1       3   \n\n\u003e\u003e\u003e cm.print_normalized_matrix()\nPredict       0             1             2             \nActual\n0             1.0           0.0           0.0           \n\n1             0.0           0.33333       0.66667       \n\n2             0.33333       0.16667       0.5          \n\n\u003e\u003e\u003e cm.stat(summary=True)\nOverall Statistics : \n\nACC Macro                                                         0.72222\nF1 Macro                                                          0.56515\nFPR Macro                                                         0.22222\nKappa                                                             0.35484\nOverall ACC                                                       0.58333\nPPV Macro                                                         0.56667\nSOA1(Landis \u0026 Koch)                                               Fair\nTPR Macro                                                         0.61111\nZero-one Loss                                                     5\n\nClass Statistics :\n\nClasses                                                           0             1             2             \nACC(Accuracy)                                                     0.83333       0.75          0.58333       \nAUC(Area under the ROC curve)                                     0.88889       0.61111       0.58333       \nAUCI(AUC value interpretation)                                    Very Good     Fair          Poor          \nF1(F1 score - harmonic mean of precision and sensitivity)         0.75          0.4           0.54545       \nFN(False negative/miss/type 2 error)                              0             2             3             \nFP(False positive/type 1 error/false alarm)                       2             1             2             \nFPR(Fall-out or false positive rate)                              0.22222       0.11111       0.33333       \nN(Condition negative)                                             9             9             6             \nP(Condition positive or support)                                  3             3             6             \nPOP(Population)                                                   12            12            12            \nPPV(Precision or positive predictive value)                       0.6           0.5           0.6           \nTN(True negative/correct rejection)                               7             8             4             \nTON(Test outcome negative)                                        7             10            7             \nTOP(Test outcome positive)                                        5             2             5             \nTP(True positive/hit)                                             3             1             3             \nTPR(Sensitivity, recall, hit rate, or true positive rate)         1.0           0.33333       0.5 \n\n```\n\n### Direct CM\n\n```pycon\n\u003e\u003e\u003e from pycm import *\n\u003e\u003e\u003e cm2 = ConfusionMatrix(matrix={\"Class1\": {\"Class1\": 1, \"Class2\": 2}, \"Class2\": {\"Class1\": 0, \"Class2\": 5}})\n\u003e\u003e\u003e cm2\npycm.ConfusionMatrix(classes: ['Class1', 'Class2'])\n\u003e\u003e\u003e cm2.classes\n['Class1', 'Class2']\n\u003e\u003e\u003e cm2.print_matrix()\nPredict      Class1       Class2       \nActual\nClass1       1            2            \n\nClass2       0            5            \n\n\u003e\u003e\u003e cm2.print_normalized_matrix()\nPredict       Class1        Class2        \nActual\nClass1        0.33333       0.66667       \n\nClass2        0.0           1.0 \n\n\u003e\u003e\u003e cm2.stat(summary=True)\nOverall Statistics : \n\nACC Macro                                                         0.75\nF1 Macro                                                          0.66667\nFPR Macro                                                         0.33333\nKappa                                                             0.38462\nOverall ACC                                                       0.75\nPPV Macro                                                         0.85714\nSOA1(Landis \u0026 Koch)                                               Fair\nTPR Macro                                                         0.66667\nZero-one Loss                                                     2\n\nClass Statistics :\n\nClasses                                                           Class1        Class2        \nACC(Accuracy)                                                     0.75          0.75          \nAUC(Area under the ROC curve)                                     0.66667       0.66667       \nAUCI(AUC value interpretation)                                    Fair          Fair          \nF1(F1 score - harmonic mean of precision and sensitivity)         0.5           0.83333       \nFN(False negative/miss/type 2 error)                              2             0             \nFP(False positive/type 1 error/false alarm)                       0             2             \nFPR(Fall-out or false positive rate)                              0.0           0.66667       \nN(Condition negative)                                             5             3             \nP(Condition positive or support)                                  3             5             \nPOP(Population)                                                   8             8             \nPPV(Precision or positive predictive value)                       1.0           0.71429       \nTN(True negative/correct rejection)                               5             1             \nTON(Test outcome negative)                                        7             1             \nTOP(Test outcome positive)                                        1             7             \nTP(True positive/hit)                                             1             5             \nTPR(Sensitivity, recall, hit rate, or true positive rate)         0.33333       1.0\n     \n```\n\n* `matrix()` and `normalized_matrix()` renamed to `print_matrix()` and `print_normalized_matrix()` in `version 1.5`\n\n### Activation threshold\n\n`threshold` is added in `version 0.9` for real value prediction.\nFor more information visit [Example3](http://www.pycm.io/doc/Example3.html \"Example3\")\n\n### Load from file\n\n`file` is added in `version 0.9.5` in order to load saved confusion matrix with `.obj` format generated by `save_obj` method.\n\nFor more information visit [Example4](http://www.pycm.io/doc/Example4.html \"Example4\")\n\n### Sample weights\n\n`sample_weight` is added in `version 1.2`\n\nFor more information visit [Example5](http://www.pycm.io/doc/Example5.html \"Example5\")\n\n### Transpose\n\n`transpose` is added in `version 1.2` in order to transpose input matrix (only in `Direct CM` mode)\n\n### Relabel\n\n`relabel` method is added in `version 1.5` in order to change ConfusionMatrix classnames.\n\n```pycon\n\u003e\u003e\u003e cm.relabel(mapping={0: \"L1\", 1: \"L2\", 2: \"L3\"})\n\u003e\u003e\u003e cm\npycm.ConfusionMatrix(classes: ['L1', 'L2', 'L3'])\n```\n\n### Position\n\n`position` method is added in `version 2.8` in order to find the indexes of observations in `predict_vector` which made TP, TN, FP, FN.\n\n```pycon\n\u003e\u003e\u003e cm.position()\n{0: {'FN': [], 'FP': [0, 7], 'TP': [1, 4, 9], 'TN': [2, 3, 5, 6, 8, 10, 11]}, 1: {'FN': [5, 10], 'FP': [3], 'TP': [6], 'TN': [0, 1, 2, 4, 7, 8, 9, 11]}, 2: {'FN': [0, 3, 7], 'FP': [5, 10], 'TP': [2, 8, 11], 'TN': [1, 4, 6, 9]}}\n```\n\n### To array\n\n`to_array` method is added in `version 2.9` in order to returns the confusion matrix in the form of a NumPy array. This can be helpful to apply different operations over the confusion matrix for different purposes such as aggregation, normalization, and combination.\n\n```pycon\n\u003e\u003e\u003e cm.to_array()\narray([[3, 0, 0],\n       [0, 1, 2],\n       [2, 1, 3]])\n\u003e\u003e\u003e cm.to_array(normalized=True)\narray([[1.     , 0.     , 0.     ],\n       [0.     , 0.33333, 0.66667],\n       [0.33333, 0.16667, 0.5    ]])\n\u003e\u003e\u003e cm.to_array(normalized=True, one_vs_all=True, class_name=\"L1\")\narray([[1.     , 0.     ],\n       [0.22222, 0.77778]])\n```\n\n### Combine\n\n`combine` method is added in `version 3.0` in order to merge two confusion matrices. This option will be useful in mini-batch learning.\n\n```pycon\n\u003e\u003e\u003e cm_combined = cm2.combine(cm3)\n\u003e\u003e\u003e cm_combined.print_matrix()\nPredict      Class1       Class2       \nActual\nClass1       2            4            \n\nClass2       0            10           \n\n```\n\n### Plot\n\n`plot` method is added in `version 3.0` in order to plot a confusion matrix using Matplotlib or Seaborn.\n\n```pycon\n\u003e\u003e\u003e cm.plot()\n```\n\n\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/plot1.png\"\u003e\n\n```pycon\n\u003e\u003e\u003e from matplotlib import pyplot as plt\n\u003e\u003e\u003e cm.plot(cmap=plt.cm.Greens, number_label=True, plot_lib=\"matplotlib\")\n```\n\n\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/plot2.png\"\u003e\t\t\n\n```pycon\n\u003e\u003e\u003e cm.plot(cmap=plt.cm.Reds, normalized=True, number_label=True, plot_lib=\"seaborn\")\n```\n\n\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/plot3.png\"\u003e\n\n### ROC curve\n\n`ROCCurve`, added in `version 3.7`, is devised to compute the Receiver Operating Characteristic (ROC) or simply ROC curve. In ROC curves, the Y axis represents the True Positive Rate, and the X axis represents the False Positive Rate. Thus, the ideal point is located at the top left of the curve, and a larger area under the curve represents better performance. ROC curve is a graphical representation of binary classifiers' performance. In PyCM, `ROCCurve` binarizes the output based on the \"One vs. Rest\" strategy to provide an extension of ROC for multi-class classifiers. Getting the actual labels vector, the target probability estimates of the positive classes, and the list of ordered labels of classes, this method is able to compute and plot TPR-FPR pairs for different discrimination thresholds and compute the area under the ROC curve.\n\n```pycon\n\u003e\u003e\u003e crv = ROCCurve(actual_vector=np.array([1, 1, 2, 2]), probs=np.array([[0.1, 0.9], [0.4, 0.6], [0.35, 0.65], [0.8, 0.2]]), classes=[2, 1])\n\u003e\u003e\u003e crv.thresholds\n[0.1, 0.2, 0.35, 0.4, 0.6, 0.65, 0.8, 0.9]\n\u003e\u003e\u003e auc_trp = crv.area()\n\u003e\u003e\u003e auc_trp[1]\n0.75\n\u003e\u003e\u003e auc_trp[2]\n0.75\n```\n\n### Precision-Recall curve\n\n`PRCurve`, added in `version 3.7`, is devised to compute the Precision-Recall curve in which the Y axis represents the Precision, and the X axis represents the Recall of a classifier. Thus, the ideal point is located at the top right of the curve, and a larger area under the curve represents better performance. Precision-Recall curve is a graphical representation of binary classifiers' performance. In PyCM, `PRCurve` binarizes the output based on the \"One vs. Rest\" strategy to provide an extension of this curve for multi-class classifiers. Getting the actual labels vector, the target probability estimates of the positive classes, and the list of ordered labels of classes, this method is able to compute and plot Precision-Recall pairs for different discrimination thresholds and compute the area under the curve.\n\n```pycon\n\u003e\u003e\u003e crv = PRCurve(actual_vector=np.array([1, 1, 2, 2]), probs=np.array([[0.1, 0.9], [0.4, 0.6], [0.35, 0.65], [0.8, 0.2]]), classes=[2, 1])\n\u003e\u003e\u003e crv.thresholds\n[0.1, 0.2, 0.35, 0.4, 0.6, 0.65, 0.8, 0.9]\n\u003e\u003e\u003e auc_trp = crv.area()\n\u003e\u003e\u003e auc_trp[1]\n0.29166666666666663\n\u003e\u003e\u003e auc_trp[2]\n0.29166666666666663\n```\n\n### Parameter recommender\n\nThis option has been added in `version 1.9` to recommend the most related parameters considering the characteristics of the input dataset.\nThe suggested parameters are selected according to some characteristics of the input such as being balance/imbalance and binary/multi-class.\nAll suggestions can be categorized into three main groups: imbalanced dataset, binary classification for a balanced dataset, and multi-class classification for a balanced dataset.\nThe recommendation lists have been gathered according to the respective paper of each parameter and the capabilities which had been claimed by the paper.\n\n```pycon\n\u003e\u003e\u003e cm.imbalance\nFalse\n\u003e\u003e\u003e cm.binary\nFalse\n\u003e\u003e\u003e cm.recommended_list\n['MCC', 'TPR Micro', 'ACC', 'PPV Macro', 'BCD', 'Overall MCC', 'Hamming Loss', 'TPR Macro', 'Zero-one Loss', 'ERR', 'PPV Micro', 'Overall ACC']\n\n```\n\n`is_imbalanced` parameter has been added in `version 3.3`, so the user can indicate whether the concerned dataset is imbalanced or not. As long as the user does not provide any information in this regard, the automatic detection algorithm will be used.\n\n```pycon\n\u003e\u003e\u003e cm = ConfusionMatrix(y_actu, y_pred, is_imbalanced=True)\n\u003e\u003e\u003e cm.imbalance\nTrue\n\u003e\u003e\u003e cm = ConfusionMatrix(y_actu, y_pred, is_imbalanced=False)\n\u003e\u003e\u003e cm.imbalance\nFalse\n```\n\n### Compare\n\nIn `version 2.0`, a method for comparing several confusion matrices is introduced. This option is a combination of several overall and class-based benchmarks. Each of the benchmarks evaluates the performance of the classification algorithm from good to poor and give them a numeric score. The score of good and poor performances are 1 and 0, respectively.\n\nAfter that, two scores are calculated for each confusion matrices, overall and class-based. The overall score is the average of the score of seven overall benchmarks which are Landis \u0026 Koch, Cramer, Matthews, Goodman-Kruskal's Lambda A, Goodman-Kruskal's Lambda B, Krippendorff's Alpha, and Pearson's C. In the same manner, the class-based score is the average of the score of six class-based benchmarks which are Positive Likelihood Ratio Interpretation, Negative Likelihood Ratio Interpretation, Discriminant Power Interpretation, AUC value Interpretation, Matthews Correlation Coefficient Interpretation and Yule's Q Interpretation. It should be noticed that if one of the benchmarks returns none for one of the classes, that benchmarks will be eliminated in total averaging. If the user sets weights for the classes, the averaging over the value of class-based benchmark scores will transform to a weighted average.\n\nIf the user sets the value of `by_class` boolean input `True`, the best confusion matrix is the one with the maximum class-based score. Otherwise, if a confusion matrix obtains the maximum of both overall and class-based scores, that will be reported as the best confusion matrix, but in any other case, the compared object doesn’t select the best confusion matrix.\n\n```pycon\n\u003e\u003e\u003e cm2 = ConfusionMatrix(matrix={0: {0: 2, 1: 50, 2: 6}, 1: {0: 5, 1: 50, 2: 3}, 2: {0: 1, 1: 7, 2: 50}})\n\u003e\u003e\u003e cm3 = ConfusionMatrix(matrix={0: {0: 50, 1: 2, 2: 6}, 1: {0: 50, 1: 5, 2: 3}, 2: {0: 1, 1: 55, 2: 2}})\n\u003e\u003e\u003e cp = Compare({\"cm2\": cm2, \"cm3\": cm3})\n\u003e\u003e\u003e print(cp)\nBest : cm2\n\nRank  Name   Class-Score       Overall-Score\n1     cm2    0.50278           0.58095\n2     cm3    0.33611           0.52857\n\n\u003e\u003e\u003e cp.best\npycm.ConfusionMatrix(classes: [0, 1, 2])\n\u003e\u003e\u003e cp.sorted\n['cm2', 'cm3']\n\u003e\u003e\u003e cp.best_name\n'cm2'\n```\n\n### Multilabel confusion matrix\n\nFrom `version 4.0`, `MultiLabelCM` has been added to calculate class-wise or sample-wise multilabel confusion matrices. In class-wise mode, confusion matrices are calculated for each class, and in sample-wise mode, they are generated per sample. All generated confusion matrices are binarized with a one-vs-rest transformation.\n\n```pycon\n\u003e\u003e\u003e mlcm = MultiLabelCM(actual_vector=[{\"cat\", \"bird\"}, {\"dog\"}], predict_vector=[{\"cat\"}, {\"dog\", \"bird\"}], classes=[\"cat\", \"dog\", \"bird\"])\n\u003e\u003e\u003e mlcm.actual_vector_multihot\n[[1, 0, 1], [0, 1, 0]]\n\u003e\u003e\u003e mlcm.predict_vector_multihot\n[[1, 0, 0], [0, 1, 1]]\n\u003e\u003e\u003e mlcm.get_cm_by_class(\"cat\").print_matrix()\nPredict 0       1       \nActual\n0       1       0       \n\n1       0       1       \n\n\u003e\u003e\u003e mlcm.get_cm_by_sample(0).print_matrix()\nPredict 0       1       \nActual\n0       1       0       \n\n1       1       1 \n\n```\n\n### Online help\n\n`online_help` function is added in `version 1.1` in order to open each statistics definition in web browser\n\n```pycon\n\u003e\u003e\u003e from pycm import online_help\n\u003e\u003e\u003e online_help(\"J\")\n\u003e\u003e\u003e online_help(\"SOA1(Landis \u0026 Koch)\")\n\u003e\u003e\u003e online_help(2)\n```\n\n* List of items are available by calling `online_help()` (without argument)\n* If PyCM website is not available, set `alt_link = True` (new in `version 2.4`)\n\n### Screen record\n\n\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://asciinema.org/a/171863\" target=\"_blank\"\u003e\u003cimg src=\"https://asciinema.org/a/171863.png\"/\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## Try PyCM in your browser!\n\nPyCM can be used online in interactive Jupyter Notebooks via the Binder or Colab services! Try it out now! :\n\n[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/sepandhaghighi/pycm/master)\n\n[![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/sepandhaghighi/pycm/blob/master)\n\n* Check `Examples` in `Document` folder\n\n## Issues \u0026 bug reports\n\n1. Fill an issue and describe it. We'll check it ASAP!\n    - Please complete the issue template\n2. Discord : [https://discord.com/invite/zqpU2b3J3f](https://discord.com/invite/zqpU2b3J3f)\n3. Website : [https://www.pycm.io](https://www.pycm.io)\n4. Mailing List : [https://mail.python.org/mailman3/lists/pycm.python.org/](https://mail.python.org/mailman3/lists/pycm.python.org/)\n5. Email : [info@pycm.io](mailto:info@pycm.io \"info@pycm.io\")\n\n## Acknowledgments\n\n[NLnet foundation](https://nlnet.nl) has supported the PyCM project from version **3.6** to **4.0** through the [NGI Assure](https://nlnet.nl/assure) Fund. This fund is set up by [NLnet foundation](https://nlnet.nl) with funding from the European Commission's [Next Generation Internet program](https://ngi.eu), administered by DG Communications Networks, Content, and Technology under grant agreement [**No 957073**](https://nlnet.nl/project/PyCM/).\n\n\u003ca href=\"https://nlnet.nl\"\u003e\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/NlNet.svg\" height=\"50px\" alt=\"NLnet foundation\"\u003e\u003c/a\u003e \u0026nbsp;  \u003ca href=\"https://nlnet.nl/assure\"\u003e\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/NGIAssure.svg\" height=\"50px\" alt=\"NGI Assure\"\u003e\u003c/a\u003e\n\n[Python Software Foundation (PSF)](https://www.python.org/psf/) grants PyCM library partially for version **3.7**. [PSF](https://www.python.org/psf/) is the organization behind Python. Their mission is to promote, protect, and advance the Python programming language and to support and facilitate the growth of a diverse and international community of Python programmers.\n\n\u003ca href=\"https://www.python.org/psf/\"\u003e\u003cimg src=\"https://github.com/sepandhaghighi/pycm/raw/master/Otherfiles/PSF.png\" height=\"55px\" alt=\"Python Software Foundation\"\u003e\u003c/a\u003e\n\nSome parts of the infrastructure for this project are supported by:\n\u003cp\u003e\n  \u003ca href=\"https://www.digitalocean.com/\"\u003e\n    \u003cimg src=\"https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg\" width=\"201px\" alt=\"DigitalOcean\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Cite\n\nIf you use PyCM in your research, we would appreciate citations to the following paper:\n\n\n[Haghighi, S., Jasemi, M., Hessabi, S. and Zolanvari, A., 2018. PyCM: Multiclass confusion matrix library in Python. *Journal of Open Source Software*, 3(25), p.729.](https://joss.theoj.org/papers/10.21105/joss.00729)\n\n\n```bibtex\n@article{Haghighi2018,\n  doi = {10.21105/joss.00729},\n  url = {https://doi.org/10.21105/joss.00729},\n  year  = {2018},\n  month = {may},\n  publisher = {The Open Journal},\n  volume = {3},\n  number = {25},\n  pages = {729},\n  author = {Sepand Haghighi and Masoomeh Jasemi and Shaahin Hessabi and Alireza Zolanvari},\n  title = {{PyCM}: Multiclass confusion matrix library in Python},\n  journal = {Journal of Open Source Software}\n}\n```\n\nDownload [PyCM.bib](http://www.pycm.io/PYCM.bib)\n\n\u003ctable\u003e\n\t\u003ctr\u003e \n\t\t\u003ctd align=\"center\"\u003eJOSS\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://doi.org/10.21105/joss.00729\"\u003e\u003cimg src=\"http://joss.theoj.org/papers/10.21105/joss.00729/status.svg\"\u003e\u003c/a\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\t\u003ctr\u003e\n\t\t\u003ctd align=\"center\"\u003eZenodo\u003c/td\u003e\n\t\t\u003ctd align=\"center\"\u003e\u003ca href=\"https://doi.org/10.5281/zenodo.1157173\"\u003e\u003cimg src=\"https://zenodo.org/badge/DOI/10.5281/zenodo.1157173.svg\" alt=\"DOI\"\u003e\u003c/a\u003e\u003c/td\u003e\n\t\u003c/tr\u003e\n\u003c/table\u003e\n\n## Show your support\n\n### Star this repo\n\nGive a ⭐️ if this project helped you!\n\n### Donate to our project\n\nIf you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) .\n\n\u003ca href=\"http://www.pycm.io/donate.html\" target=\"_blank\"\u003e\u003cimg src=\"http://www.pycm.io/images/Donate-Button.png\" height=\"90px\" width=\"270px\" alt=\"PyCM Donation\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsepandhaghighi%2Fpycm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsepandhaghighi%2Fpycm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsepandhaghighi%2Fpycm/lists"}