Save Confusion Matrix in Python SKLEARN
12,925
I fixed the problem I was having. In case anyone is wondering, I modified the code to this and it resolved the problem.
for matrix in confusion_matrices:
fig = plt.figure()
plt.matshow(cm)
plt.title('Problem 1: Confusion Matrix Digit Recognition')
plt.colorbar()
plt.ylabel('True Label')
plt.xlabel('Predicated Label')
plt.savefig('confusion_matrix'+str(learning_values.pop())+'.jpg')
Related videos on Youtube
Author by
James Musk
Updated on June 04, 2022Comments
-
James Musk almost 2 years
I'm generating 6 different confusion matrices for 6 different values of training data and I'm trying to save the generated confusion matrices as images. Unfortunately, when they save they keep saving as blank jpeg images; however, when I use show() to display them they are visible. Here is my code
for matrix in confusion_matrices: fig = plt.figure() plt.matshow(cm) plt.title('Problem 1: Confusion Matrix Digit Recognition') plt.colorbar() plt.ylabel('True Label') plt.xlabel('Predicated Label') fig.savefig('confusion_matrix'+str(learning_values.pop())+'.jpg')
I'm using the following libraries:
import matplotlib.pyplot as plt import numpy from numpy import ravel, reshape, swapaxes import scipy.io from sklearn import svm from sklearn.metrics import confusion_matrix from random import sample
How do I efficiently save confusion matrices?
-
Warren Weckesser over 8 yearsWhere is
saveas
defined? Just a guess: whateversaveas
is, perhaps it requires thatplt.show()
has been called beforesaveas
is called. Have you triedplt.savefig(...)
?
-