简体   繁体   English

在 Python SKLEARN 中保存混淆矩阵

[英]Save Confusion Matrix in Python SKLEARN

I'm generating 6 different confusion matrices for 6 different values of training data and I'm trying to save the generated confusion matrices as images.我正在为 6 个不同的训练数据值生成 6 个不同的混淆矩阵,并且我正在尝试将生成的混淆矩阵保存为图像。 Unfortunately, when they save they keep saving as blank jpeg images;不幸的是,当他们保存时,他们一直保存为空白的 jpeg 图像; however, when I use show() to display them they are visible.但是,当我使用 show() 来显示它们时,它们是可见的。 Here is my code这是我的代码

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

I'm using the following libraries:我正在使用以下库:

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

How do I efficiently save confusion matrices?如何有效地保存混淆矩阵?

I fixed the problem I was having.我解决了我遇到的问题。 In case anyone is wondering, I modified the code to this and it resolved the problem.如果有人想知道,我修改了代码并解决了这个问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM