pretty-confusion-matrix


Namepretty-confusion-matrix JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/wcipriano/pretty-print-confusion-matrix
Summaryplot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib
upload_time2024-05-04 05:21:13
maintainerNone
docs_urlNone
authorWagner Cipriano
requires_python<3.12,>=3.8
licenseNone
keywords confusion matrix
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Confusion Matrix in Python
Plot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib

Created on Mon Jun 25 14:17:37 2018
@author: Wagner Cipriano - wagnerbhbr


This module get a pretty print confusion matrix from a NumPy matrix or from 2 NumPy arrays (`y_test` and `predictions`).

## Installation
```bash
pip install pretty-confusion-matrix
```

## Get Started

Examples:
```python
import numpy as np
import pandas as pd
from pretty_confusion_matrix import pp_matrix

array = np.array([[13,  0,  1,  0,  2,  0],
                  [0, 50,  2,  0, 10,  0],
                  [0, 13, 16,  0,  0,  3],
                  [0,  0,  0, 13,  1,  0],
                  [0, 40,  0,  1, 15,  0],
                  [0,  0,  0,  0,  0, 20]])

# get pandas dataframe
df_cm = pd.DataFrame(array, index=range(1, 7), columns=range(1, 7))
# colormap: see this and choose your more dear
cmap = 'PuRd'
pp_matrix(df_cm, cmap=cmap)
```
![alt text](https://raw.githubusercontent.com/khuyentran1401/pretty-print-confusion-matrix/master/Screenshots/Conf_matrix_default.png)

```python
import numpy as np
from pretty_confusion_matrix import pp_matrix_from_data

y_test = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,
                  3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])
predic = np.array([1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 3, 4, 4, 1, 4, 3, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 3, 5, 1, 2, 3, 3, 5, 1, 2,
                  3, 4, 4, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])

pp_matrix_from_data(y_test, predic)
```

![alt text](https://raw.githubusercontent.com/khuyentran1401/pretty-print-confusion-matrix/master/Screenshots/Conf_matrix_default_2.png)



## References:
### 1. MATLAB confusion matrix:

a) [Plot Confusion](https://www.mathworks.com/help/nnet/ref/plotconfusion.html)
   
b) [Plot Confusion Matrix Using Categorical Labels](https://www.mathworks.com/help/examples/nnet/win64/PlotConfusionMatrixUsingCategoricalLabelsExample_02.png)



### 2. Examples and more on Python:

  a) [How to plot confusion matrix with string axis rather than integer in python](https://stackoverflow.com/questions/5821125/how-to-plot-confusion-matrix-with-string-axis-rather-than-integer-in-python/51176855#51176855)
  
  b) [Plot-scikit-learn-classification-report](https://stackoverflow.com/questions/28200786/how-to-plot-scikit-learn-classification-report)
  
  c) [Plot-confusion-matrix-with-string-axis-rather-than-integer-in-Python](https://stackoverflow.com/questions/5821125/how-to-plot-confusion-matrix-with-string-axis-rather-than-integer-in-python)
  
  d) [Seaborn heatmap](https://www.programcreek.com/python/example/96197/seaborn.heatmap)
  
  e) [Sklearn-plot-confusion-matrix-with-labels](https://stackoverflow.com/questions/19233771/sklearn-plot-confusion-matrix-with-labels/31720054)

  f) [Model-selection-plot-confusion-matrix](http://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html#sphx-glr-auto-examples-model-selection-plot-confusion-matrix-py)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/wcipriano/pretty-print-confusion-matrix",
    "name": "pretty-confusion-matrix",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.12,>=3.8",
    "maintainer_email": null,
    "keywords": "confusion matrix",
    "author": "Wagner Cipriano",
    "author_email": "wagnao@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8d/a8/59f2b2c6e9a188b6cdc6a79ad3433c3e1b6609946103f98139ce7097b02a/pretty_confusion_matrix-0.2.0.tar.gz",
    "platform": null,
    "description": "# Confusion Matrix in Python\nPlot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib\n\nCreated on Mon Jun 25 14:17:37 2018\n@author: Wagner Cipriano - wagnerbhbr\n\n\nThis module get a pretty print confusion matrix from a NumPy matrix or from 2 NumPy arrays (`y_test` and `predictions`).\n\n## Installation\n```bash\npip install pretty-confusion-matrix\n```\n\n## Get Started\n\nExamples:\n```python\nimport numpy as np\nimport pandas as pd\nfrom pretty_confusion_matrix import pp_matrix\n\narray = np.array([[13,  0,  1,  0,  2,  0],\n                  [0, 50,  2,  0, 10,  0],\n                  [0, 13, 16,  0,  0,  3],\n                  [0,  0,  0, 13,  1,  0],\n                  [0, 40,  0,  1, 15,  0],\n                  [0,  0,  0,  0,  0, 20]])\n\n# get pandas dataframe\ndf_cm = pd.DataFrame(array, index=range(1, 7), columns=range(1, 7))\n# colormap: see this and choose your more dear\ncmap = 'PuRd'\npp_matrix(df_cm, cmap=cmap)\n```\n![alt text](https://raw.githubusercontent.com/khuyentran1401/pretty-print-confusion-matrix/master/Screenshots/Conf_matrix_default.png)\n\n```python\nimport numpy as np\nfrom pretty_confusion_matrix import pp_matrix_from_data\n\ny_test = np.array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2,\n                  3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])\npredic = np.array([1, 2, 4, 3, 5, 1, 2, 4, 3, 5, 1, 2, 3, 4, 4, 1, 4, 3, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 3, 5, 1, 2, 3, 3, 5, 1, 2,\n                  3, 4, 4, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 3, 4, 1, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 4, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])\n\npp_matrix_from_data(y_test, predic)\n```\n\n![alt text](https://raw.githubusercontent.com/khuyentran1401/pretty-print-confusion-matrix/master/Screenshots/Conf_matrix_default_2.png)\n\n\n\n## References:\n### 1. MATLAB confusion matrix:\n\na) [Plot Confusion](https://www.mathworks.com/help/nnet/ref/plotconfusion.html)\n   \nb) [Plot Confusion Matrix Using Categorical Labels](https://www.mathworks.com/help/examples/nnet/win64/PlotConfusionMatrixUsingCategoricalLabelsExample_02.png)\n\n\n\n### 2. Examples and more on Python:\n\n  a) [How to plot confusion matrix with string axis rather than integer in python](https://stackoverflow.com/questions/5821125/how-to-plot-confusion-matrix-with-string-axis-rather-than-integer-in-python/51176855#51176855)\n  \n  b) [Plot-scikit-learn-classification-report](https://stackoverflow.com/questions/28200786/how-to-plot-scikit-learn-classification-report)\n  \n  c) [Plot-confusion-matrix-with-string-axis-rather-than-integer-in-Python](https://stackoverflow.com/questions/5821125/how-to-plot-confusion-matrix-with-string-axis-rather-than-integer-in-python)\n  \n  d) [Seaborn heatmap](https://www.programcreek.com/python/example/96197/seaborn.heatmap)\n  \n  e) [Sklearn-plot-confusion-matrix-with-labels](https://stackoverflow.com/questions/19233771/sklearn-plot-confusion-matrix-with-labels/31720054)\n\n  f) [Model-selection-plot-confusion-matrix](http://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html#sphx-glr-auto-examples-model-selection-plot-confusion-matrix-py)\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "plot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/wcipriano/pretty-print-confusion-matrix",
        "Repository": "https://github.com/wcipriano/pretty-print-confusion-matrix"
    },
    "split_keywords": [
        "confusion",
        "matrix"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45a2b150f06a7498bccec05d1d9d36037c28f0312d62523de46580316055cb18",
                "md5": "5de9f9d8b8ae7503a4615849ffc2fc8e",
                "sha256": "dfac53274984c61c0c467d5e98cc23bc5f9daac92a6d77d18fb9423d6ebc9f43"
            },
            "downloads": -1,
            "filename": "pretty_confusion_matrix-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5de9f9d8b8ae7503a4615849ffc2fc8e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.8",
            "size": 9738,
            "upload_time": "2024-05-04T05:21:11",
            "upload_time_iso_8601": "2024-05-04T05:21:11.446369Z",
            "url": "https://files.pythonhosted.org/packages/45/a2/b150f06a7498bccec05d1d9d36037c28f0312d62523de46580316055cb18/pretty_confusion_matrix-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8da859f2b2c6e9a188b6cdc6a79ad3433c3e1b6609946103f98139ce7097b02a",
                "md5": "80b9fafc07703885a6debffa68da5ede",
                "sha256": "9e6b7c72a1fad25cd15447b4154fe6142e05fa3a51eb92119ed85a7ea4bbe8e8"
            },
            "downloads": -1,
            "filename": "pretty_confusion_matrix-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "80b9fafc07703885a6debffa68da5ede",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.8",
            "size": 8818,
            "upload_time": "2024-05-04T05:21:13",
            "upload_time_iso_8601": "2024-05-04T05:21:13.344053Z",
            "url": "https://files.pythonhosted.org/packages/8d/a8/59f2b2c6e9a188b6cdc6a79ad3433c3e1b6609946103f98139ce7097b02a/pretty_confusion_matrix-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-04 05:21:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wcipriano",
    "github_project": "pretty-print-confusion-matrix",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pretty-confusion-matrix"
}
        
Elapsed time: 0.23853s