定义性能评估指标
def performances(y_true, y_pred, y_prob):
tn, fp, fn, tp = confusion_matrix(y_true, y_pred, labels = [0, 1]).ravel().tolist()
accuracy = (tp+tn)/(tn+fp+fn+tp)
try:
recall = tp / (tp+fn)
except:
recall = 0
try:
precision = tp / (tp+fp)
except:
precision = 0
try:
f1 = 2*precision*recall / (precision+recall)
except:
f1 = 0
roc_auc = roc_auc_score(y_true, y_prob)
prec, reca, _ = precision_recall_curve(y_true, y_prob)
aupr = auc(reca, prec)
print('tn = {}, fp = {}, fn = {}, tp = {}'.format(tn, fp, fn, tp))
print('y_pred: 0 = {} | 1 = {}'.format(Counter(y_pred)[0], Counter(y_pred)[1]))
print('y_true: 0 = {} | 1 = {}'.