【问题标题】:Unable to Print the Complete Confusion Matrix in Python [duplicate]无法在 Python 中打印完整的混淆矩阵 [重复]
【发布时间】:2019-01-05 15:07:20
【问题描述】:

我正在构建一个图像预测模型。

为了更好地了解准确性,我正在使用scikit learn 打印混淆矩阵。

当我使用 30 个类时,混淆矩阵完全显示在打印屏幕上,但是当我在 50 个类上使用我的模型时,它开始打印混淆矩阵的截断/缩小版本。

我尝试了不同的方法来完成打印或将其写入文件,但它不起作用。

输出是这样的:

[[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
...
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]
[0 0 0 ... 0 0 0]]

我也试过np.set_printoptions。但它也不起作用。

使用 np.set_printoptions 它甚至不让我打印任何东西,我得到如下错误:typeError can not implement between int and str

【问题讨论】:

标签: python deep-learning prediction evaluation confusion-matrix


【解决方案1】:

您可以将数组转换为列表,然后打印出来:

my_list = my_array.tolist()

【讨论】:

    【解决方案2】:

    通过设置可以打印完整的数组而不截断

    np.set_printoptions(threshold=np.inf)
    

    np.set_printoptions(threshold=np.nan)
    

    默认情况下,超过 1000 个元素的数组将被截断。

    有关完整文档,请参阅http://docs.scipy.org/doc/numpy/reference/generated/numpy.set_printoptions.html

    【讨论】:

    • 嗨卡米尔,正如我在问题中提到的,它给了我一个错误或我猜的类型转换:typeError 无法在 int 和 str 之间实现。
    • 您不能不通过 str 作为阈值。它必须是整数,例如 np.set_printoptions(threshold=5000)
    • 你使用的是哪个 numpy 版本?
    猜你喜欢
    • 2018-09-17
    • 1970-01-01
    • 2020-11-17
    • 2019-11-24
    • 2020-10-01
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多