分类模型的精确率(precision)与召回率(recall)(Python)

  • TP:true positive,将正类预测为正类
  • FN:false negative,将正类预测为负类
  • FP:false positive,将负类预测为正类
  • TN:true negative,将负类预测为负类



伪阳性率FPR(False Positive Rate,在真实为阴性的样本中,被误诊为阴性的比率,在真实为阴性(FP+TN)的样本中,被误诊为阳性(FP)的比值):

FPR=FPFP+TN F P R = F P F P + T N

真阳性率TPR(True Positive Rate,在真实为阳性的样本中,被正确诊断为阳性的比率为):
TPR=TPTP+FN T P R = T P T P + F N

Precision(精确率)

P=TPTP+FP P = T P T P + F P

Recall(召回率)(FN:false negative,真实为 positive,预测为 negative,伪阴):
R=TPTP+FN R = T P T P + F N

F1 score:
2F1=1P+1RF1=2PRP+R 2 F 1 = 1 P + 1 R F 1 = 2 P R P + R

# y_true, y_pred
# TP = (y_pred==1)*(y_true==1)
# FP = (y_pred==1)*(y_true==0)
# FN = (y_pred==0)*(y_true==1)
# TN = (y_pred==0)*(y_true==0)
# TP + FP = y_pred==1
# TP + FN = y_true==1

def precision_score(y_true, y_pred):
    return ((y_true==1)*(y_pred==1)).sum()/(y_pred==1).sum()
def recall_score(y_true, y_pred):
    return ((y_true==1)*(y_pred==1)).sum()/(y_true==1).sum()
def f1_score(y_true, y_pred):
    num = 2*precison_score(y_true, y_pred)*recall_score(y_true, y_pred)
    deno = (precision_score(y_true, y_pred)+recall_score(y_true, y_pred))
    return num/deno
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五道口纳什

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值