Pretty Confusion Matrix

Why pretty confusion matrix?

  • We can make confusion matrix by using matplotlib.
  • However it is not so pretty. I want to make confusion matrix prettier.

How to Install?

pip install prettycm

Full Code Example

from prettycm import confusion_matrix
from prettycm import palette

pset = palette(size=5, color="blue")
cm = confusion_matrix([[400,0,0,0],[0,156,8,14],[0,18,131,30],[0,60,28,75]])
cm.set_classname(["Acute", "Non-resolving","Normal","Inactive"])
cm.set_title("Retinal Specialist2")
pset.draw(cm, "place_to_save.png")

Result of generated confusion matrix

How to Use? Explain more detail

  1. import package from prettycm

from prettycm import confusion_matrix
from prettycm import palette
  1. build confusion matrix object

cm = confusion_matrix([[10,20],[30,3]])
cm.set_classname(["Lion", "Tiger"]) # You can set the class name.
cm.set_title("Lion or Tiger?") # You can set the title.
  • the input of the confusion_matrix must be two-dimensional array
  • Python list or numpy array are both allowed
  • You can set the name of the class and title.
  1. define palette object
pset = palette(size=5, color="blue")
  • size = the quality and size of output confusion matrix image
  • color = the color of confusion matrix. (Now only blue is supported)
  1. draw confusion matrix and save
pset.draw(confusion_matrix=cm, path="place_to_save.png")
  • confusion_matrix: put confusion matrix object
  • path: path to save

Done

  1. Special function
print(cm)
  • When you print confusion_matrix object, than python will print the confusion matrix like below

Update Plans

1. More color presets

  • Blue
  • Red
  • Green
  • Purple

2. Confusion matrix concat

  • Concat two confusion matrix

3. Pallet Function

  • Text Size control
  • Cleaning the code

Contribute to project

  1. Pull requests after you modify code.
  2. Make more color presets.

GitHub

View Github