机器学习FP、TP、FN、TN、sensitivity、specificity及代码实现

目录

一、概念整理

二、应用指标

三、代码实现


一、概念整理

第一个字母T/F代表预测结果y_pred是否和实际情况y_test相符

第二个字母P/N代表预测结果的正负

  • TP:true positive,被判定为正样本,实际上也是正样本
  • TN:true negative,被判定为负样本,实际上也是负样本
  • FP:false positive,被判定为正样本,实际上是负样本
  • FN:false negative,被判定为负样本,实际上是正样本

二、应用指标

三、代码实现

confusion_matrix = confusion_matrix(y_test, y_pred)


[返回值]: ndarray of shape (n_classes, n_classes)


Confusion matrix whose i-th row and j-th column entry indicates the number of samples with true label being i-th class and predicted label being j-th class. 

例如:confution_matrix = array([[28,  7],
                                [ 3, 23]])

其中:n_classes = 2,class=0为负样本N,class=1为正样本P

  • 28 -> 真值为0,预测为0 的样本数量 -> TN
  • 7  ->  真值为0,预测为1 的样本数量 -> FP
  • 3  ->  真值为1,预测为0 的样本数量 -> FN
  • 23 -> 真值为1,预测为1 的样本数量 -> TP
confusion_matrix = confusion_matrix([0, 1, 0, 1], [1, 1, 1, 0])
# confusion_matrix = [[0 2],
#                     [1 1]]
tn, fp, fn, tp = confusion_matrix([0, 1, 0, 1], [1, 1, 1, 0]).ravel()
# (tn, fp, fn, tp) = (0,2,1,1)


sensitivity = confusion_matrix[1,1]/(confusion_matrix[1,1]+confusion_matrix[1,0])
print('Sensitivity : ', sensitivity )

specificity = confusion_matrix[0,0]/(confusion_matrix[0,0]+confusion_matrix[0,1])
print('Specificity : ', specificity)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值