How can I plot in Python a Confusion Matrix similar do the one shown here for already given values of the Confusion Matrix?
In the code they use the method sklearn.metrics.plot_confusion_matrix which computes the Confusion Matrix based on the ground truth and the predictions.
But in my case, I already have calculated my Confusion Matrix. So for example, my Confusion Matrix is (values in percentages):
[[0.612, 0.388]
[0.228, 0.772]]
I saw that someone already answered this question, but I'm adding a new one that can be useful for the author or even for other users.
It is possible to plot in Python an already Confusion Matrix computed through mlxtend package:
Mlxtend (machine learning extensions) is a Python library of useful tools for the day-to-day data science tasks.
Snippet code:
# Imports
from mlxtend.plotting import plot_confusion_matrix
import matplotlib.pyplot as plt
import numpy as np
# Your Confusion Matrix
cm = np.array([[0.612, 0.388],
[0.228, 0.772]])
# Classes
classes = ['class A', 'class B']
figure, ax = plot_confusion_matrix(conf_mat = cm,
class_names = classes,
show_absolute = False,
show_normed = True,
colorbar = True)
plt.show()
The output will be:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With