Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

python - Sort multi label confusion matrix

I'm beginner of machine learning and do now multi label problem for my thesis using fastai.

I made a confusion matrix but wanna show only 5 classes which are not good predicted. This is a result of my confusion matrix

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

to visualize my matrix, i used the above code. enter image description here

so i wanna only show pear and tomato which have more FP.

Do anyone know how to implement it?

question from:https://stackoverflow.com/questions/65952380/sort-multi-label-confusion-matrix

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...