Plot a pretty confusion matrix in Python with MATLAB like style.
The Pretty Confusion Matrix in Python with MATLAB like style, using seaborn and matplotlib.
This repository was forked and modified from Wagner’s Pretty print confusion matrix.
Example:
git clone https://github.com/phongsathorn1/pretty-confusion-matrix.git
pip install -r requirements.txt
Plot from numpy y_predict
and y_actual
vectors
from pretty_cm import plot_from_data
y_actual = np.array([1,2,3,4,5, 1,2,3,4,5, ...])
y_predict = np.array([1,2,4,3,5, 1,2,3,4,4, ...])
plot_from_data(y_actual, y_predict)
Plot from numpy confusion matrix
from pretty_cm import plot_from_confusion_matrix
cm = 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]])
plot_from_confusion_matrix(cm)
Plot with custom labels
plot_from_data(y_test, predic,
columns=["Dog", "Cat", "Potato", "Car", "IU <3"])
# -- or --
plot_from_confusion_matrix(cm, columns=["Dog", "Cat", "Potato", "Car", "IU <3"])
Result:
Change figure size
plot_from_data(y_test, predic, figsize=[6,6])
# -- or --
plot_from_confusion_matrix(cm, figsize=[6,6])
The Pretty Confusion Matrix is licensed under Apache License, Version 2.0. see License for full license text.