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:
1. MATLAB confusion matrix:
b) Plot Confusion Matrix Using Categorical Labels
2. Examples and more on Python:
a) How to plot confusion matrix with string axis rather than integer in python
b) Plot-scikit-learn-classification-report
c) Plot-confusion-matrix-with-string-axis-rather-than-integer-in-Python
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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e6b7c72a1fad25cd15447b4154fe6142e05fa3a51eb92119ed85a7ea4bbe8e8 |
|
MD5 | 80b9fafc07703885a6debffa68da5ede |
|
BLAKE2b-256 | 8da859f2b2c6e9a188b6cdc6a79ad3433c3e1b6609946103f98139ce7097b02a |
Close
Hashes for pretty_confusion_matrix-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfac53274984c61c0c467d5e98cc23bc5f9daac92a6d77d18fb9423d6ebc9f43 |
|
MD5 | 5de9f9d8b8ae7503a4615849ffc2fc8e |
|
BLAKE2b-256 | 45a2b150f06a7498bccec05d1d9d36037c28f0312d62523de46580316055cb18 |