import numpy as np
from sklearn.metrics import confusion_matrix,accuracy_score,f1_score,roc_auc_score,recall_score,precision_score
def calculate_metric(gt, pred):
pred[pred>0.5]=1
pred[pred<1]=0
confusion = confusion_matrix(gt,pred)
TP = confusion[1, 1]
TN = confusion[0, 0]
FP = confusion[0, 1]
FN = confusion[1, 0]
print('Accuracy:',(TP+TN)/float(TP+TN+FP+FN))
print('Sensitivity:',TP / float(TP+FN))
print('Specificity:',TN / float(TN+FP))
path = "OS3_val_result.csv"
with open(path, 'r') as f:
file_list = f.read()
file_list = file_list.split('\n')[1:-1]
file_list = [file.split(',') for file in file_list]
y = np.array([float(y[1]) for y in file_list])
preds2 = np.array([float(preds[2]) for preds in file_list])
preds3 = np.array([float(preds[3]) for preds in file_list])
preds4 = np.array([float(preds[4]) for preds in file_list])
auc = roc_auc_score(y,preds2)
print('AUC:',auc)
calculate_metric(y,preds2)
auc = roc_auc_score(y,preds3)
print('AUC:',auc)
calculate_metric(y,preds3)
auc = roc_auc_score(y,preds4)
print('AUC:',auc)
calculate_metric(y,preds4)
来源:CSDN
作者:愿十四亿神州尽舜尧
链接:https://blog.csdn.net/weixin_41783077/article/details/103886139