分类评价指标

有些东西虽然简单,但是还是要过个7、8遍才不容易记混记乱。

在这里插入图片描述

  1. Accuracy

  2. Sensitivity
    在患病的所有人中(已经明确知道数据的分布了!),预测正确(判断为有病)的有多少?
    S e n s i t i v i t y = T P T P + F N Sensitivity = \frac{TP}{TP + FN} Sensitivity=TP+FNTP

  3. Specificity
    在未患病的所有人中(已经明确知道数据的分布了!),预测正确(判断为没病)的有多少?
    S p e c i f i c i t y = T N T N + F P Specificity=\frac{TN}{TN + FP} Specificity=TN+FPTN

  4. Recall
    Sensitivity = Recall;再提一遍——已经明确知道数据的分布了!

  5. Precision
    预测的都是有病的人中,真正有病的人有多少——查准率。
    P r e c i s i o n = T P T P + F P Precision = \frac{TP}{TP + FP} Precision=TP+FPTP

  6. PPV-positive predictive value
    预测的都是有病的人中,真正有病的人有多少——查准率。
    P P V = T P T P + F P PPV = \frac{TP}{TP + FP} PPV=TP+FPTP
    ⚠️: PPV = Precision

  7. NPV-negative predictive value
    在预测的所有没有病的人中,真正没病的人所占的比例。
    N P V = T N T N + F N NPV = \frac{TN}{TN + FN} NPV=TN+FNTN

  8. AUC - ROC曲线下方的面积大小
    ROC:参考维基百科

从AUC判断分类器(预测模型)优劣的标准:

  • AUC = 1,是完美分类器,采用这个预测模型时,存在至少一个阈值能得出完美预测。绝大多数预测的场合,不存在完美分类器。
  • 0.5 < AUC < 1,优于随机猜测。这个分类器(模型)妥善设定阈值的话,能有预测价值。
  • AUC = 0.5,跟随机猜测一样(例:丢铜板),模型没有预测价值。
  • AUC < 0.5,比随机猜测还差;但只要总是反预测而行,就优于随机猜测。

CODE

Sensitivity(Recall):

def Sensitivity(y_true, y_pred):
    """
    param:
    y_pred - Predicted labels
    y_true - True labels 
    Returns:
    Sensitivity score
    """
    neg_y_true = 1 - y_true
    neg_y_pred = 1 - y_pred
    fn = np.sum(neg_y_pred * y_true)
    tp = np.sum(y_true * y_pred)
    
    sensitivity = tp / (tp + fn)
    return sensitivity

Specificity:

def specificity(y_true, y_pred):
    """
    param:
    y_pred - Predicted labels
    y_true - True labels 
    Returns:
    Specificity score
    """
    neg_y_true = 1 - y_true
    neg_y_pred = 1 - y_pred
    fp = np.sum(neg_y_true * y_pred)
    tn = np.sum(neg_y_true * neg_y_pred)
    specificity = tn / (tn + fp)
    return specificity

PPV(Precision):

def PPV(y_true, y_pred):
    """
    param:
    y_pred - Predicted labels
    y_true - True labels 
    Returns:
    PPV score
    """
    neg_y_true = 1 - y_true
    neg_y_pred = 1 - y_pred
    fp = np.sum(neg_y_pred * y_true)
    tp = np.sum(y_true * y_pred)
    
    PPV = tp / (tp + fp)
    return PPV

NPV:

def NPV(y_true, y_pred):
    """
    param:
    y_pred - Predicted labels
    y_true - True labels 
    Returns: NPV
    """
    neg_y_true = 1 - y_true
    neg_y_pred = 1 - y_pred

    tn = np.sum(neg_y_true * neg_y_pred)
    
    NPV = tn / np.sum(neg_y_pred)
    return NPV
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值