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
Release history Release notifications | RSS feed
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
Close
Hashes for pretty-confusion-matrix-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 733a1a552459f15836c1bc0e4c491d252b6bb89a481ec58100a778f50f8f98cd |
|
MD5 | b02920d31bebbda4c2ecb23c52ba60ef |
|
BLAKE2b-256 | 324267337f407b04677367629533f64b18a8723f2ba3b59883ac647260c1ab97 |
Close
Hashes for pretty_confusion_matrix-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a742bc1304728bdb6f73fe7ced9e1b8c4e83bba75909eaa9683f57ef0b5cd2c |
|
MD5 | a4533610c9571258381dd09ed443cb17 |
|
BLAKE2b-256 | e3c94e9887f23cab910a489a2a62e2880e5ace1ddf5801bde9fac92512d6e650 |