def plot_confusion_matrix(cm, labels_name, title): cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] # 归一化 plt.imshow(cm, interpolation='nearest', cmap="summer") # 在特定的窗口上显示图像 plt.title(title) # 图像标题 plt.colorbar() num_local = np.array(range(len(labels_name))) plt.xticks(num_local, labels_name) # 将标签印在x轴坐标上 plt.yticks(num_local, labels_name, rotation=90) # 将标签印在y轴坐标上 plt.ylabel('True label') plt.xlabel('Predicted label') predicted = np.argmax(resultall, 1) confu_matrix = cal_confu_matrix(np.array(predicted), np.array(lableforconfusion), class_num=2) print(confu_matrix) labels_name = ["inactive CNV", "active CNV"] plot_confusion_matrix(confu_matrix, labels_name, "Confusion Matrix") plt.savefig('./savedimg/confusionmatrix_octa.png', dpi=300, bbox_inches='tight') plt.show() metrics(confu_matrix, save_path="./savedimg/") for i in range(n_classes): fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i]) roc_auc[i] = auc(fpr[i], tpr[i])
label='Doctor3', tick_label=name_list, fc='plum') plt.legend(loc="upper left", bbox_to_anchor=(0.0, 1.1), ncol=4) plt.savefig('./savedimg/OCT/CNN_Doctor_precission_comparision_EACH.png', dpi=300) plt.show() #draw recall bar pic each from metrics import calc_metrics, cal_confu_matrix, metrics import numpy as np aaaaaa = np.array(data['A']) confu_matrix = cal_confu_matrix(np.array(data['A']), np.array(data['D']), class_num=4) print(confu_matrix) metrics(confu_matrix, save_path="./savedimg/OCT/doctor1") confu_matrix = cal_confu_matrix(np.array(data['B']), np.array(data['D']), class_num=4) print(confu_matrix) metrics(confu_matrix, save_path="./savedimg/OCT/doctor2") confu_matrix = cal_confu_matrix(np.array(data['C']), np.array(data['D']), class_num=4) print(confu_matrix) metrics(confu_matrix, save_path="./savedimg/OCT/doctor3")