python - 在 Python SKLEARN 中保存混淆矩阵

标签 python numpy matplotlib scikit-learn confusion-matrix

我正在为 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

如何有效地保存混淆矩阵?

最佳答案

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

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

关于python - 在 Python SKLEARN 中保存混淆矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32558952/

相关文章:

python - 添加多个重叠立方体的矢量化方式

python - matplotlib 中的文本对象无法正确响应缩放

python - 如何将 matplotlib 图导出为带有可编辑文本字段的矢量图形?

python - re.sub 只替换两次

Python 参数化

python - 通过沿轴应用 tuple() 沿轴挤压 ndarray

python - python给我的解决方案是什么 "ValueError: setting an array element with a sequence."

macos - 在 Matplotlib 的 LATEX 中使用\text

python - PyCharm 代码检查不包括 PEP 8

python - 如何从字典列表转换为字典?