plot a pretty confusion matrix (like Matlab) in python using seaborn and matplotlib
Project description
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
pip install pretty-confusion-matrix
Get Started
Examples:
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)
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)
References:
-
Mat lab confusion matrix
-
Other Examples in python
a) https://stackoverflow.com/a/51176855/1809554
b) https://www.programcreek.com/python/example/96197/seaborn.heatmap
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pretty-confusion-matrix-0.1.1.tar.gz
.
File metadata
- Download URL: pretty-confusion-matrix-0.1.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.4.0-81-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2ad7a258da40ac893b258ce7dde2e1460874247ccda4c54e293f942aabe959 |
|
MD5 | de44123b50523fbf63692a9a176bd06a |
|
BLAKE2b-256 | 86df58bd1765f2597c1b04da5807ae4ee9e28d1ba87da7b58ac065c1f0417f38 |
File details
Details for the file pretty_confusion_matrix-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pretty_confusion_matrix-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.8.10 Linux/5.4.0-81-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44ddce7f470987f4590c4ddd87dc2c10e9e0bd1fd131515c9a5462be085a2c46 |
|
MD5 | d14a906c2e4201e87f3fc05e507c2167 |
|
BLAKE2b-256 | db9aea05b89261ef4971402286279facde7e54fab13312eaf75388048a628802 |