排序多标签混淆矩阵

时间:2021-01-29 10:04:30

标签: python machine-learning confusion-matrix

我是机器学习的初学者,现在使用 fastai 为我的论文做多标签问题。

我制作了一个混淆矩阵,但只想显示 5 个预测不好的类。 这是我的混淆矩阵的结果

array([[[48,  1],
        [ 0, 10]],

       [[50,  0],
        [ 0,  9]],

       [[49,  0],
        [ 0, 10]],

       [[47,  2],
        [ 0, 10]],

       [[44,  5],
        [ 0, 10]],

       [[42,  7],
        [ 0, 10]]])
def print_confusion_matrix(confusion_matrix, axes, class_label, class_names, fontsize=14):

    df_cm = pd.DataFrame(
        confusion_matrix, index=class_names, columns=class_names,
    )

    try:
        heatmap = sns.heatmap(df_cm, annot=True, fmt="d", cbar=False, ax=axes)
    except ValueError:
        raise ValueError("Confusion matrix values must be integers.")
    heatmap.yaxis.set_ticklabels(heatmap.yaxis.get_ticklabels(), rotation=0, ha='right', fontsize=fontsize)
    heatmap.xaxis.set_ticklabels(heatmap.xaxis.get_ticklabels(), rotation=45, ha='right', fontsize=fontsize)
    axes.set_xlabel('Predicted')
    axes.set_ylabel('Actual')
    axes.set_title(class_label)
fig, ax = plt.subplots(4, 4, figsize=(12, 7))
    
for axes, cfs_matrix, label in zip(ax.flatten(), mcm, fruits.vocab):
        print_confusion_matrix(cfs_matrix, axes, label, ["N", "P"])
    
fig.tight_layout()
plt.show()

为了可视化我的矩阵,我使用了上面的代码。 enter image description here

所以我只想展示具有更多 FP 的梨和番茄。

有人知道如何实现吗?

0 个答案:

没有答案