项目作者: phongsathorn1

项目描述 :
Plot a pretty confusion matrix in Python with MATLAB like style.
高级语言: Python
项目地址: git://github.com/phongsathorn1/pretty-confusion-matrix.git
创建时间: 2021-02-12T04:43:20Z
项目社区:https://github.com/phongsathorn1/pretty-confusion-matrix

开源协议:Apache License 2.0

下载


Pretty Confusion Matrix for Python

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:

Example of Pretty Confusion Matrix

Installation

  • Clone this repository:
    1. git clone https://github.com/phongsathorn1/pretty-confusion-matrix.git
  • Install required packages:
    1. pip install -r requirements.txt

Usage

  • Plot from numpy y_predict and y_actual vectors

    1. from pretty_cm import plot_from_data
    2. y_actual = np.array([1,2,3,4,5, 1,2,3,4,5, ...])
    3. y_predict = np.array([1,2,4,3,5, 1,2,3,4,4, ...])
    4. plot_from_data(y_actual, y_predict)
  • Plot from numpy confusion matrix

    1. from pretty_cm import plot_from_confusion_matrix
    2. cm = np.array([[13, 0, 1, 0, 2, 0],
    3. [ 0, 50, 2, 0, 10, 0],
    4. [ 0, 13, 16, 0, 0, 3],
    5. [ 0, 0, 0, 13, 1, 0],
    6. [ 0, 40, 0, 1, 15, 0],
    7. [ 0, 0, 0, 0, 0, 20]])
    8. plot_from_confusion_matrix(cm)
  • Plot with custom labels

    1. plot_from_data(y_test, predic,
    2. columns=["Dog", "Cat", "Potato", "Car", "IU <3"])
    3. # -- or --
    4. plot_from_confusion_matrix(cm, columns=["Dog", "Cat", "Potato", "Car", "IU <3"])

    Result:

    Example of Pretty Confusion Matrix

  • Change figure size

    1. plot_from_data(y_test, predic, figsize=[6,6])
    2. # -- or --
    3. plot_from_confusion_matrix(cm, figsize=[6,6])

Licensing

The Pretty Confusion Matrix is licensed under Apache License, Version 2.0. see License for full license text.

References:

  1. MATLAB confusion matrix