【发布时间】:2015-12-10 02:37:43
【问题描述】:
我正在为 6 个不同的训练数据值生成 6 个不同的混淆矩阵,并且我正在尝试将生成的混淆矩阵保存为图像。不幸的是,当他们保存时,他们会继续保存为空白 jpeg 图像;但是,当我使用 show() 显示它们时,它们是可见的。这是我的代码
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是什么,也许它要求plt.show()已被调用之前saveas被调用。你试过plt.savefig(...)吗? -
嗨,Warren,感谢您指出我犯的那个愚蠢的错误。但是,现在我将其更改为上面的代码,它仍然没有保存。还有其他想法吗?
标签: python numpy matplotlib scikit-learn confusion-matrix