0
我为6个不同的训练数据值生成6个不同的混淆矩阵,我试图将生成的混淆矩阵保存为图像。不幸的是,当他们保存时,他们一直保存为空白的jpeg图像;然而,当我使用show()来显示它们时,它们是可见的。这里是我的代码在Python中保存混淆矩阵SKLEARN
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')
我使用下列库:
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
如何有效地避免混淆矩阵?
'saveas'定义在哪里?只是一个猜测:无论'saveas'是什么,也许它需要在调用'saveas'之前调用'plt.show()'。你尝试过'plt.savefig(...)'吗? –
嗨沃伦,谢谢你指出我犯的那个愚蠢的错误。但是,现在我已将其更改为上面的代码,但仍未保存。任何其他想法? –