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(...)'嗎? –
嗨沃倫,謝謝你指出我犯的那個愚蠢的錯誤。但是,現在我已將其更改爲上面的代碼,但仍未保存。任何其他想法? –