【问题标题】:Save Confusion Matrix in Python SKLEARN在 Python SKLEARN 中保存混淆矩阵
【发布时间】: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


【解决方案1】:

我解决了我遇到的问题。如果有人想知道,我将代码修改为此并解决了问题。

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')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2021-09-29
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    相关资源
    最近更新 更多