我编写了以下函数来在 Python/matplotlib 中绘制混淆矩阵:
def print_conf_mat(y_test, y_pred):
conf_mat = confusion_matrix(y_test, y_pred)
classes = ['Normal', 'Type 1', 'Type 2', 'Type 3', 'Type 4', 'Type 5', 'Type 6']
imshow(conf_mat, interpolation='nearest', cmap=cm.Blues)
print('Confusion matrix:')
colorbar()
tick_marks = arange(len(classes))
xticks(tick_marks, classes, rotation=45)
yticks(tick_marks, classes)
fmt = 'd'
thresh = conf_mat.max() / 2.
for i, j in product(range(conf_mat.shape[0]), range(conf_mat.shape[1])):
text(j, i, format(conf_mat[i, j], fmt),
horizontalalignment="center",
color="white" if conf_mat[i, j] > thresh else "black")
xlabel('Predicted label')
ylabel('True label')
tight_layout()
figure()
show()
Run Code Online (Sandbox Code Playgroud)
我得到以下格式的矩阵:
我想去掉烦人的那句
<Figure size 432x288 with 0 Axes>
Run Code Online (Sandbox Code Playgroud)
关于我如何实现这一目标的任何线索?
小智 0
在其他情况下,即使没有该方法,figure()我也得到了相同的无聊尺寸。
解决方法:plt.show()如您所见添加:
fig, ax = plt.subplots(1,2,figsize=(10,10))
ax[0].imshow(RGB_image)
ax[0].set_title('RGB image')
ax[0].axis('off')
ax[1].imshow(L,cmap='gray' )
ax[1].set_title('L channel (Lightness)')
ax[1].axis('off')
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2310 次 |
| 最近记录: |