The code above defines a function called draw_result that takes in a confusion matrix C as input. The function creates a heatmap visualization of the confusion matrix using the sns.heatmap function from the seaborn library. It also calculates and prints out various evaluation metrics such as accuracy, precision, NAR (Negative Accuracy Rate), and F1 score for each class.

The resulting heatmap is saved as a JPEG image file called "CNN_confusion_matrix.jpg". The function also displays the heatmap using the plt.show() function.

The accuracy is calculated by summing the diagonal elements of the confusion matrix and dividing it by the sum of all elements in the matrix.

The precision is calculated by dividing the true positive (diagonal) element of each class by the sum of the corresponding row in the confusion matrix.

The NAR is calculated by dividing the sum of the false positive elements (sum of each row excluding the diagonal element) by the sum of the corresponding row in the confusion matrix.

The F1 score is calculated using the formula: 2 * (true positive / (true positive + false positive)) / (true positive + false negative).

The function prints out the accuracy, precision, NAR, and F1 score for each class.

def draw_resultC fig = pltfigure ax = figadd_subplot111 df = pdDataFrameC # f1 = fmfontPropertiesTimes New Roman size=15 snsheatmapdf fmt=g annot=True annot_kws=size 10

原文地址: https://www.cveoy.top/t/topic/ibPL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录