Skip to content

phongsathorn1/pretty-confusion-matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:
    git clone https://github.com/phongsathorn1/pretty-confusion-matrix.git
  • Install required packages:
    pip install -r requirements.txt

Usage

  • 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:

    Example of Pretty Confusion Matrix
  • Change figure size

    plot_from_data(y_test, predic, figsize=[6,6])
    
    # -- or --
    
    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

Releases

No releases published

Packages

No packages published

Languages